google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: C program create a student struct accept details of n students into structure rearrange data in alphabetical order of stud name and display result.

Wednesday, April 1, 2015

C program create a student struct accept details of n students into structure rearrange data in alphabetical order of stud name and display result.

Write a ‘C’ program to create a student structure having field stud name and address. Accept the details of ‘n’ students into the structure rearrange the data in alphabetical order of stud name and display the result.

#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
{
char sname[20];
char add[20];
};
void main()
{
struct student s[10];
char ch[20];
int i,j,n;
clrscr();
printf("enter the student");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the sname&add");
for(i=0;i<n;i++)
{
scanf("%s%s",&s[i].sname,&s[i].add);
}
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(&s[i].sname,&s[j].sname)>0)
{
strcpy(ch,&s[i].sname);
strcpy(&s[i].sname,&s[i].sname);
strcpy(&s[j].sname,ch);
}
}
}
for(i=0;i<n;i++)
{
printf("%s",s[i].sname);
}
getch();
}

अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...