/*write a c program to create a student structure having the field
stud_name,address. accept the details of n student is structure
and rearrange the data in alphabetical order of stud_name and
display the result*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
struct stud
{
char stud_name[20];
char address[20];
};
struct stud s[5];
int i,j,p,m;
char n[30],temp[30];
clrscr();
printf("\nhow many student :\n");
scanf("%d",&m);
for(i=0;i<m;i++)
{
printf("\nenter the name :");
flushall();
scanf("%s",&s[i].stud_name);
printf("\neneter the address :");
flushall();
scanf("%s",&s[i].address);
}
for(i=0;i<m;i++)
{
for(j=i+1;j<m;j++)
{
p=strcmp(s[i].stud_name,s[j].stud_name);
if(p>0)
{
strcpy(temp,s[j].stud_name);
strcpy(s[j].stud_name,s[i].stud_name);
strcpy(s[i].stud_name,temp);
strcpy(n,s[i].address);
strcpy(s[i].address,s[j].address);
strcpy(s[j].address,n);
}
}
}
printf("\nrearrangement of data in alphabetical order of name :\n");
printf("\nname\taddress\n");
for(i=0;i<m;i++)
{
printf("%s\t%s\n",s[i].stud_name,s[i].address);
}
getch();
}
/*
how many student :
4
enter the name :peer
eneter the address :pune
enter the name :santosh
eneter the address :kareal
enter the name :eahul
eneter the address :hjk
enter the name :pema
eneter the address :khadki
rearrangement of data in alphabetical order of name :
name address
eahul hjk
peer pune
pema khadki
santosh kareal
*/
No comments:
Post a Comment