Array of Structures
#include<stdio.h>
struct
student
{
char
name[20];
int rollno;
float mark;
int rollno;
float mark;
};
main()
{
struct student S[10];
int
i, n;
printf("\nEnter
the number of students: ");
scanf("%d",
&n);
for(i=0;
i<n; i++)
{
printf("\nEnter name rollno and
mark of a student %d: ", i+1);
scanf("%s
%d %f", S[i].name, &S[i].rollno, &S[i].mark );
}
for(i=0; i<n; i++)
{
printf("\nStudent
%d details: ", i+1);
printf("\n
\tName is %s \n\tRollno is %d \n\tMark is %f", S[i].name, S[i].rollno,
S[i].mark );
}
}
Output:
Enter the
number of students: 3
Enter name
rollno and mark of a student 1: aaa 10 55
Enter name
rollno and mark of a student 2: bbb 20 66
Enter name
rollno and mark of a student 3: ccc 30 77
Student 1
details:
Name is aaa
Rollno is 10
Mark is 55.000000
Student 2
details:
Name is bbb
Rollno is 20
Mark is 66.000000
Student 3
details:
Name is ccc
Rollno is 30
Mark is 77.000000Goto Main Content:
https://tejaswinihbhat.blogspot.in/2016/07/data-structures-15CS33-Module1.html
https://tejaswinihbhat.blogspot.in/2016/07/structures.html
No comments:
Post a Comment