C program to store the roll number , name ,and marks of a student using structure and sort the names in order of maximum marks to minimum marks
This C program using structure sort student name in order max to min marks i.e. to store the roll number , name ,and marks of a student using structure and sort the names in order of maximum marks to minimum marks.
Basically one should know how to write the syntax of a structure and the rest is just implementation of the programs done so far.
If you yet need a dry run of the program or any other query, then kindly leave a comment in the comment box or mail me, I would be more than happy to help you.
Program
#include<stdio.h> struct student { int roll_no,marks; char name[25]; }stud[100],t; void main() { int i,j,n; printf("Enter the no of students\n"); scanf("%d",&n); printf("enter student info as roll_no , name , marks\n"); for(i=0;i<n;i++) { scanf("%d %s %d",&stud[i].roll_no,stud[i].name,&stud[i].marks); } for(i=0;i<n;i++) { for(j=0;j<n-1;j++) { if(stud[j].marks<stud[j+1].marks) { t=stud[j]; stud[j]=stud[j+1]; stud[j+1]=t; } } } printf("\nStudent info in terms of marks from highest to lowest\n"); printf("\nROLL_NO\t\tNAME\t\tMARKS\n"); printf("-------------------------------------------------------------------------------\n"); for(i=0;i<n;i++) { printf("%d\t\t\t%s\t\t\t%d\n",stud[i].roll_no,stud[i].name,stud[i].marks); } }