Write a Modular C Programming code for Getting details of a Student who took the highest marks.
Read the number of students, read their information and display the details of the students:
CODE:
#include<stdio.h> struct student { char name[20]; int rno; float marks; }; struct student s[50]; void read(struct student s[50], int n); void display(struct student s[50], int n); void avgmarks(struct student s[50], int n); void maxmarks(struct student s[50], int n); int n, i; main() { printf("Enter the no. of students you want to give info: "); scanf("%d",&n); printf("\nEnter Details of Student %d",i+1); read(s,n); avgmarks(s,n); maxmarks(s,n); } void read(struct student s[50], int n) { for(i=0;i<n;i++) { printf("\nEnter the Name: "); scanf("%s",&s[i].name); printf("Enter the RollNo: "); scanf("%d",&s[i].rno); printf("Enter the Marks: "); scanf("%f",&s[i].marks); printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n"); } } void avgmarks(struct student s[50], int n) { int sum=0; float avg; for(i=0;i<n;i++) { sum=sum+s[i].marks; } } void display(struct student s[50], int n) { printf("\nName: %s",s[n].name); printf("\nRollNo: %d",s[n].rno); printf("\nMarks: %f",s[n].marks); printf("\n\n+++++++++++++++++++++++++++++++++++++++++++++++++\n"); } void maxmarks(struct student s[50], int n) { int max=s[0].marks,k; for(i=0;i<n;i++) { if (s[i].marks>max) { max=s[i].marks; k=i; } } printf("The Details of Student who took Highest Marks is:\n"); display(s,k); }
OUTPUT
Enter the no. of students you want to give info: 5 Enter Details of Student 1 Enter the Name: rhhyt Enter the RollNo: 67 Enter the Marks: 657 +++++++++++++++++++++++++++++++++++++++++++++++++ Enter the Name: thyju Enter the RollNo: 657 Enter the Marks: 75 +++++++++++++++++++++++++++++++++++++++++++++++++ Enter the Name: kkkkkk Enter the RollNo: 7777 Enter the Marks: 8888888 +++++++++++++++++++++++++++++++++++++++++++++++++ Enter the Name: ujy Enter the RollNo: 78 Enter the Marks: 76 +++++++++++++++++++++++++++++++++++++++++++++++++ Enter the Name: utjy Enter the RollNo: 67 Enter the Marks: 76 +++++++++++++++++++++++++++++++++++++++++++++++++ The Details of Student who took Highest Marks is: Name: kkkkkk RollNo: 7777 Marks: 8888888.000000 +++++++++++++++++++++++++++++++++++++++++++++++++ Process returned 0 (0x0) execution time : 20.005 s Press any key to continue.
Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:
Top 100+ C Programming codes – KLE Technological University