C Array of Structure
Why use an array of structures?
An array of structres in C can be defined as the collection of multiple structures variables where each variable contains information about different entities. The array of structure in c are used to store information about multiple entities of different data types. The array of structures is also known as the collection of structures.
Program of array of structure
#include<stdio.h>
struct student
{
char name[20];
int id;
float marks;
};
void main()
{
struct student s1,s2,s3;
int dummy;
printf("Enter the name, id, and marks of student 1 ");
scanf("%s %d %f",s1.name,&s1.id,&s1.marks);
scanf("%c",&dummy);
printf("Enter the name, id, and marks of student 2 ");
scanf("%s %d %f",s2.name,&s2.id,&s2.marks);
scanf("%c",&dummy);
printf("Enter the name, id, and marks of student 3 ");
scanf("%s %d %f",s3.name,&s3.id,&s3.marks);
scanf("%c",&dummy);
printf("Printing the details....\n");
printf("%s %d %f\n",s1.name,s1.id,s1.marks);
printf("%s %d %f\n",s2.name,s2.id,s2.marks);
printf("%s %d %f\n",s3.name,s3.id,s3.marks);
}
Output
Enter the name, id, and marks of student 1 Pramod 90 90
Enter the name, id, and marks of student 2 Amit90 90
Enter the name, id, and marks of student 3 Ankit 90 90
Printing the details....
Pramod 90 90.000000
Amit 90
90.000000
Ankit 90 90.000000
No comments:
Post a Comment