Showing posts with label Array within Structure. Show all posts
Showing posts with label Array within Structure. Show all posts

Tuesday 27 March 2012

Array within Structure




C permits the use of arrays as structure members.
Ex
struct stud
{
          int sno;
          char sname[15];
          int m[3];
};

void main()
{
          struct  stud s[5];
          int i,j;
         
          for(i=0;i<5;i++)
          {
                   printf(“\n Enter No :”);
                   scanf(“%d”,&s[i].sno);
                   fflush(stdin);
                   printf(“\n Enter Name:”);
                   gets(s[i].name);
         
                   for(j=0;j<3;j++)
                   {
                             printf(“\n Enter mark :”);
                             scanf(“%d”,&s[i].m[j]);
                   }

          }

for(i=0;i<5;i++)
{
                   printf(“\n  No :%d”,s[i].sno);
                   printf(“\n Name :%s”,s[i].sname);

                   for(j=0;j<3;j++)
                   {
                             printf(“Mark - %d = %d “,j+1,s[i].m[j]);
                   }
}

}


Posted By :Ruchita Pandya