C PROGRAMMING

write a c program to implement array of structure

C program to implement array of structure 

   #include<stdio.h>

struct student {
char name[20];
char roll[20];
int mks;
} std[10], temp;

void main() {
int i, j, n,size;
printf("nEnter number of students : n");
scanf("%d",&size);

n=size;
for (i = 0; i < n; i++) {
printf("nEnter %d student Name : ",i+1);
scanf("%s", std[i].name);
printf("nEnter %d student Roll no : ",i+1);
scanf("%s", std[i].roll);
printf("nEnter %d student marks : ",i+1);
scanf("%d", &std[i].mks);
printf("n");
}
n=size;
for (i = 1; i < n; i++)
for (j = 0; j < n - i; j++) {
if (strcmp(std[j].roll, std[j + 1].roll) > 0) {
temp = std[j];
std[j] = std[j + 1];
std[j + 1] = temp;
}
}

for (i = 0; i < n; i++) {
printf("n%st%st%d",std[i].name,std[i].roll,std[i].mks);
}
getch();
}
Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button