Advanced Programming Programs
Array of Structure-
Example: Write a program to demonstrate the use of array
of structure.
#include<stdio.h>
#include<conio.h>
struct student
{
int rollno;
char sname[50];
char sclass[20];
char city[30];
float marks;
};
main()
{
int i;
struct student s[4]; //structure declaring
printf("--Enter information of students--\n");
for( i=0;i<4;i++)
{
printf("Enter Roll Number: ");
scanf("%d",&s[i].rollno);
printf("Enter Name of Student: ");
scanf("%s",&s[i].sname);
printf("Enter Class of Student: ");
scanf("%s",&s[i].sclass);
printf("Enter City: ");
scanf("%s",&s[i].city);
printf("Enter Student Marks: ");
scanf("%f",&s[i].marks);
}
for(i=0;i<4;i++)
{
printf("\n ------------------");
printf("\n Student Record:%d \n",i+1);
printf("\n ------------------");
printf("\n Roll is : %d\n",s[i].rollno);
printf("\n Name is : %s\n",s[i].sname);
printf("\n Class is :%s \n",s[i].sclass);
printf("\n City is : %s\n",s[i].city);
printf("\n Marks : %f \n",s[i].marks);
}
return 0;
getch();
}

Comments
Post a Comment