C Program to Read Records of n Students & Display Details of Student Having Highest Marks

Question: Write a program in C to read records of n different students in structure having member name, roll and marks, and display the student detail obtaining highest marks.

C Source Code: Records of n Students & Find Highest Marks


#include<stdio.h>

/* Declaration of structure */
struct student
{
 char name[30];
 int roll;
 float marks;
};

int main()
{
 /* Declaration of array of structure */
 struct student s[20], lg;
 int i,n;
 
 printf("Enter n:\n");
 scanf("%d",&n);
 for(i=0;i< n;i++)
 {
  printf("Enter name, roll and marks of student:\n");
  scanf("%s%d%f",s[i].name, &s[i].roll, &s[i].marks);
 }
 lg = s[0];
 for(i=0;ilg.marks)
  {
   lg = s[i];
  }
 }
 printf("Student obtaing highest marks is:\n");
 printf("Name: %s\n", lg.name);
 printf("Roll: %d\n", lg.roll);
 printf("Marks: %0.2f\n", lg.marks);
 return 0;
}

Output

The output of the above program is:

Enter n:
4 ↲
Enter name, roll and marks of student:
Ram ↲
10 ↲
88 ↲
Enter name, roll and marks of student:
Shyam ↲
11 ↲
67 ↲
Enter name, roll and marks of student:
Hari ↲
12 ↲
92 ↲
Enter name, roll and marks of student:
Prakash ↲
13 ↲
88.5 ↲
Student obtaining highest marks is:
Name: Hari
Roll: 12
Marks: 92.50

Note: ↲ represents ENTER key is pressed.