C Program to Read Records of Three Students in Structure & Displaying Details
Question: Write a program in C to read records of three different students in structure having member name, roll and marks, and display the details.
C Source Code: Read Records of Three Student in Structure
#include<stdio.h>
/* Declaration of structure */
struct student
{
char name[30];
int roll;
float marks;
};
int main()
{
/* Declaration of array of structure */
struct student s[3];
int i;
for(i=0;i< 3;i++)
{
printf("Enter name, roll and marks of student:\n");
scanf("%s%d%f",s[i].name, &s[i].roll, &s[i].marks);
}
printf("Inputted details are:\n");
for(i=0;i< 3;i++)
{
printf("Name: %s\n",s[i].name);
printf("Roll: %d\n", s[i].roll);
printf("Marks: %0.2f\n\n", s[i].marks);
}
return 0;
}
Output
The output of the above program is:
Enter name, roll and marks of student: Manjari ↲ 17 ↲ 80.5 ↲ Enter name, roll and marks of student: Monalisa ↲ 18 ↲ 90 ↲ Enter name, roll and marks of student: Manita ↲ 19 ↲ 78 ↲ Inputted details are: Name: Manjari Roll: 17 Marks: 80.50 Name: Monalisa Roll: 18 Marks: 90.00 Name: Manita Roll: 19 Marks: 78.00 Note: ↲ represents ENTER key is pressed.