Array in Structures in C

Array in Structures in C

Sometimes, it is necessary to use structure members with array.

Program :

/* Program to demonstrate array in structures.
Creation Date : 23 Nov 2010 06:07:11 PM
Author : www.technoexam.com [Technowell Web Solutions, INDIA] */

#include <stdio.h>
#include <conio.h>

struct result
{
int rno, mrks[5];
char nm;
}res;

int main(void)
{
int i,total;
clrscr();
total = 0;
printf("\n\t Enter Roll Number : ");
scanf("%d", &res.rno);
printf("\n\t Enter Marks of 3 Subjects : ");
for(i=0;i<3;i++)
{
scanf("%d",&res.mrks[i]);
total = total + res.mrks[i];
}
printf("\n\n\t Roll Number : %d", res.rno);
printf("\n\n\t Marks are :");
for(i=0;i<3;i++)
{
printf(" %d",res.mrks[i]);
}
printf("\n\n\t Total is : %d", total);
getch();
return 0;
}

Output :
Enter Roll Number : 1
Enter Marks of 3 Subjects : 63 66 68

Roll Number : 1
Marks are : 63 66 68
Total is : 197

Leave A Comment

Your email address will not be published. Required fields are marked *