0
4.4kviews
Write a program to accept marks of five student using array and print it out in ascending order
1 Answer
1
165views

C Program that show marks of students in Ascending Order

#include<stdio.h>
#include<conio.h>

struct student
{
    int Roll_No,Marks;
    char Fname[25];
}stud[100],t;

void main()
{
    int i,j,n;
    printf("Enter how many students?\n");
    scanf("%d",&n);
    printf("enter students information in the sequence of Roll Numbers, First Names and Marks\n");

// Take Students' information from the user

    for(i=0;i<n;i++)
    {
        scanf("%d %s %d",&stud[i].Roll_No,stud[i].Fname,&stud[i].Marks);
    }

//  Arrange marks obtained by Students in Ascending Order    

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(stud[j].Marks<stud[i].Marks)
            {
                t=stud[i];
                stud[i]=stud[j];
                stud[j]=t;
            }
        }
    }

// Display information of Students' in Ascending Order of Marks

    printf("\nStudents' information in Ascending Order according to Marks obtained\n");
    printf("\nROLL_NO\t\tFIRST NAME\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].Fname,stud[i].Marks);
    }
}
  • Above C program first, takes input from the user about how many students?
  • Then take students' information in the form of Roll Numbers, First Names of Students, and Marks obtained by students.
  • Then arrange students' marks in ascending order.
  • Finally, display the student information in ascending order of marks.
Please log in to add an answer.