Wednesday 20 February 2013

Array of Structure


//Array of Structure

#include<stdio.h>
struct student
{
int roll;
char name[30];
char addr[30];
char branch[30];
int age;
}stud[50];

int main()
{
int i,num;
printf("\nEnter the number of Students");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("\n %d.",i);
printf("\n Enter the Name of the student:");
scanf("%s",&stud[i].name);
printf(" Enter the Roll no:");
scanf("%d",&stud[i].roll);
printf(" Enter the Address:");
scanf("%s",&stud[i].addr);
printf(" Enter the Branch:");
scanf("%s",&stud[i].branch);
printf(" Enter the Age:");
scanf("%d",&stud[i].age);
}
printf("\n\t**The Entered Information is as follows**\n");
printf("\n**************************************************************************\n");
printf("Sr No.\tName\t\tRoll NO\t\tAddress\t\tBranch\t\tAge");
printf("\n**************************************************************************\n");
for(i=0;i<num;i++)
{
printf("%d.",i);
printf("\t%s",stud[i].name);
printf("\t\t%d",stud[i].roll);
printf("\t\t%s",stud[i].addr);
printf("\t\t%s",stud[i].branch);
printf("\t\t%d\n",stud[i].age);
}
}


1 comment:

  1. We can define an array of structure in C like array of any other data types in CArray of structure in C is similar to array of any basic data type.

    ReplyDelete