#include<stdio.h>
#include<string.h>
struct student
{
char name[20];
int roll;
};
void main()
{
struct student s[10],t;
int i,n,j;
printf("Enter no. of students : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter %dth student's name and roll : ",i+1);
scanf("%s%d",s[i].name,&s[i].roll);
}
for(i=0;i<=n-2;i++)
{
for(j=i+1;j<=n-1;j++)
{
if(strcmp(s[i].name,s[j].name)>0)
{
t=s[i];
s[i]=s[j];
s[j]=t;
}
}
}
printf("\nName sorted in alphabetical order is : ");
printf("\nName\tRoll No.");
for(i=0;i<n;i++)
{
printf("\n%s\t%d",s[i].name,s[i].roll);
}
getch();
}
Related Posts:
Arranging numbers in ascending and descending order in C#include<stdio.h>
void main()
{
int x[5],i,j,temp;
for(i=0;i<=4;i++)
{
printf("Enter x[%d]th number : ",i);
scanf("%d"… Read More
Display string after deleting vowels in it in C#include<stdio.h>
void main()
{
char str[50],i;
printf("Enter a string : ");
gets(str);
printf("\nAfter deleting vowels :\t");
for(i=0;str[i]!='\0'… Read More
Find highest paid employee in C#include<stdio.h>
struct emp
{
char name[50];
int salary;
};
void main()
{
int n,i,sum=0,avg;
struct emp e[20],ls,hs;
printf("Enter the number of emp… Read More
Operations on complex numbers in C#include<stdio.h>
struct cmplx
{
float real;
float img;
};
struct cmplx add(struct cmplx x, struct cmplx y)
{
struct cmplx z;
z.real = x.real + y.real;
&nbs… Read More
Find largest and smallest no. in C#include<stdio.h>
void main()
{
int x[10],i,j,temp;
for(i=0;i<=9;i++)
{
printf("Enter %dth number : ",i+1);
scanf("%d"… Read More
0 comments:
Post a Comment