Array of Structure
1. Write a program to display value of 5 students using array of structure.
#include<stdio.h>
#include<string.h>
struct student
{
int id;
char name[20];
char add[20];
};
int main()
{
int i;
struct student st[5];
for (i=1;i<=5;i++)
{
printf("Enter the id?");
scanf("%d",&st[i].id);
printf("Enter the name?");
scanf("%s",&st[i].name);
printf("Enter the address?");
scanf("%s",&st[i].add);
}
printf("List of data");
for(i=0;i<=5;i++)
{
printf("Roll no %d is %s whose address is %s \n",st[i].id,st[i].name,st[i].add);
}
return 0;
}
Comments
Post a Comment