Store Information of Students Using Structure
In this program, a structure, student is created. This structure has three members: name (string), roll (integer) and marks (float). Then, we created a structure array of size 5 to store information of 5 students. Using for loop, the program takes the information of 5 students from the user and displays it on the screen.
Input:
Input information of 5 students.
Output:
Display information of every student.
Sample of input:
Jack 1 34.5
Tom 2 22.9
Jone 3 80.3
Mark 4 77.2
Jane 5 60.3
Sample of output:
Roll number: 1
Name: Jack
Marks: 34.5
Roll number: 2
Name: Tom
Marks: 22.9
Roll number: 3
Name: Jone
Marks: 80.3
Roll number: 4
Name: Mark
Marks: 77.2
Roll number: 5
Name: Jane
Marks: 60.3
#include<stdio.h>
typedef struct{
int ID;
char name[20];
float C;
}Stu;
int main()
{
Stu stu[5];
int i;
for(i=0;i<5;i++)
{
scanf("%s %d %f",&(stu[i].name),&(stu[i].ID),&(stu[i].C));
}
for(i=0;i<5;i++)
{
printf("Roll number: %d\nName: %s\nMarks: %.1f\n",stu[i].ID,stu[i].name,stu[i].C);
}
return 0;
}