C Program to store the records of n Students (RollNo , Names , Branch , Year , Marks) and display the information of the topper of the class.
// Program by Akash Tripathi (@proakash256)
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
struct student
{
char RollNo[13];
char Name[1024];
char Branch[11];
int Year;
int Marks;
};
typedef struct student student;
int main()
{
int n;
printf("Enter the number of Students : ");
scanf("%d", &n);
student *st = malloc(n * (sizeof(student)));
for (int i = 0; i < n; i = i + 1)
{
printf("\nEnter the details of Student %d :\n", i);
printf("RollNo : ");
scanf("%s", st[i].RollNo);
getchar();
printf("Name : ");
gets(st[i].Name);
printf("Branch : ");
scanf("%s", st[i].Branch);
getchar();
printf("Year : ");
scanf("%d", &st[i].Year);
getchar();
printf("Marks : ");
scanf("%d", &st[i].Marks);
getchar();
}
int max = st[0].Marks;
int pos = 0;
for (int i = 0; i < n; i = i + 1)
{
if(st[i].Marks > max)
{
max = st[i].Marks;
pos = i;
}
}
printf("\nThe Topper of the class is :\n\n");
printf("RollNo : %s\n" , st[pos].RollNo);
printf("Name : %s\n" , st[pos].Name);
printf("Branch : %s\n" , st[pos].Branch);
printf("Year : %d\n" , st[pos].Year);
printf("Marks : %d\n" , st[pos].Marks);
return 0;
}
Comments
Post a Comment