by Dinesh Thakur Category: C Programming (Pratical)

In this program user ask to sort the record of multiple students merit wise. In this program structure type variable declared and a temp variable for temporary value storing. User need to establish the merit chart for sorting them. For this process user will use loop statement where user will calculate the data of students that are define on variable value. Loop statement will print all the data about student (roll no,score,name etc.). From the structure type variable.

The temp variable will hold the value for trespass the data to other variable. That after the loop process will admire the data according to Merit condition as the condition got true the sorted list will be on the screen. In the end sorted data will be print out as the result.
Problem statement:
This is c program that ask user to sort student data merit wise.

  1. Declaring variables.
  2. Using loop Statement.
  3. Print out the result on the screen.

Here is C source code for Sorting the Record of student Merit wise. The output of this program shown below.

 

#include<stdio.h>
struct student
{
          int rollno;
          char name[20];
          char college[40];
          int score;
};
void main()
    {
          struct student s[20],temp;
          int i,j,n;
          clrscr();
          printf("\nEnter no. of Students : ");
          scanf("%d",&n);
          printf("\nEnter the rollno,name,college name,score ");
          for(i=0;i<n;i++)
          scanf("%d%s%s%d",&s[i].rollno,s[i].name,s[i].college,&s[i].score);
          for(i=0;i<=n-1;i++)
          {
            for(j=0;j<=n-1;j++)
            {
                if(s[j].score<s[j+1].score)
                {
                  temp=s[j];
                  s[j]=s[j+1];
                  s[j+1]=temp;
                }
            }
          }
          printf("\nThe Merit List is :\n");
          for(j=0;j<n;j++)
          printf("%d\t%s\t%s\t%d\n",s[j].rollno,s[j].name,s[j].college,s[j].score);
          getch();
        } 

Sort the Record of Student Merit Wise

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content