C Program To Store Records of Students in An Array
C Program To Store Records of Students in An Array
Question
Define a structure, student, to store the following data about a student:
rollno (int), name (string) and marks (int)
Suppose that the class has 20 students. Use an array of 20 elements of type Student. Create a
function to read the students’ data into the array. Your program should be menu driven that
contains the following options :
Source Code
http://www.cprogrammingnotes.com/question/student-database.html 1/5
3/3/2018 C Program to Store Records of Students in an Array
#include <stdio.h>
struct student
{
int rollno;
char name[80];
int marks;
};
int main()
{
struct student data[20];
int n, choice, rollno;
return 0;
}
http://www.cprogrammingnotes.com/question/student-database.html 2/5
3/3/2018 C Program to Store Records of Students in an Array
printf("\n\nRollno\tName\tMarks\n");
for (i = 0; i < s; i++)
{
printf("%d\t%s\t%d\n", list[i].rollno, list[i].name, list[i].marks);
}
}
max = list[0].marks;
for (i = 1; i < s; i++)
{
if (list[i].marks > max)
{
max = list[i].marks;
}
}
return max;
}
Output
Result Menu :
Press 1 to display all records.
Press 2 to search a record.
Press 3 to display toppers names.
Press 0 to exit
Enter choice(0-3) : 1
Result Menu :
Press 1 to display all records.
Press 2 to search a record.
http://www.cprogrammingnotes.com/question/student-database.html 4/5
3/3/2018 C Program to Store Records of Students in an Array
Enter choice(0-3) : 2
Enter roll number to search : 103
Rollno : 103
Name : Monica
Marks : 78
Result Menu :
Press 1 to display all records.
Press 2 to search a record.
Press 3 to display toppers names.
Press 0 to exit
Enter choice(0-3) : 3
Alex
Krishna
Result Menu :
Press 1 to display all records.
Press 2 to search a record.
Press 3 to display toppers names.
Press 0 to exit
Enter choice(0-3) : 0
Next » (banking-system.html)
http://www.cprogrammingnotes.com/question/student-database.html 5/5