Write a C program to Display details of a student who have scored highest marks
#include<stdio.h>
#include<stdlib.h>
struct student {
int rollno;
char name[20];
float marks;
};
int main()
{
struct student *s;
int i,n,c=0;
float m, hm=0;
printf("enter the number of student = ");
scanf("%d",&n);
s = (struct student *) malloc(n*sizeof(struct student));
for(i=0;i<n;i++){
printf("\nEnter roll no = ");
scanf("%d",&(s+i)->rollno);
printf("Enter name = ");
scanf("%s",(s+i)->name);
printf("Enter marks = ");
scanf("%f",&(s+i)->marks);
m=(s+i)->marks;
if(m>hm)
{
hm=m;
c=i;
}
}
printf("\nroll no %d , name %s got highest marks ",(s+c)->rollno,(s+c)->name);
return 0;
}
OUTPUT :
Post a Comment
0 Comments