As
we have an array of basic data types, same way we can have an array variable of
structure.
Suppose
we want to store details of 50 students instead of declaring 50 different
variables of student type, we can declare an array of size 50 to store details
of 50 students.
Example:
struct student
{
int id;
char name[30];
float per;
};
struct student s[50];
Program:
A
C Program to enter the records of 5 students using structure.
#include<stdio.h>
#include<conio.h>
struct
stdinfo
{
int rn;
float per;
};
void
main()
{
struct stdinfo s[3];
int i;
clrscr();
for(i=1;i<=3;i++)
{
printf("\n Enter
the student roll no.:");
scanf("%d",&s[i].rn);
printf("\n Enter
the student percentage.:");
scanf("%d",&s[i].per);
}
for(i=0;i<=5;i++)
{
printf("\n Roll Number \t\t
Percentage");
printf("\n %d \t\t
%f",s[i].rn,s[i].per);
}
getch();
}
OUTPUT:
Enter the student roll no.: 1
Enter the student percentage.: 67
Enter the student roll no.: 2
Enter the student percentage.: 76
Enter the student roll no.: 3
Enter the student percentage.: 88
Roll Number Percentage
1 67
2 76
3 88
Roll Number Percentage
1 67
2 76
3 88
No comments:
Post a Comment