Published on: 12th Nov 2010    |   Last Updated on: 24th Nov 2011

Array in Structures :

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, Sangli] */

#include <stdio.h> #include <conio.h> struct result { int rno, mrks[5]; char nm; }res; void main() { 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(); }

Output :


	Enter Roll Number : 1
	
	Enter Marks of 3 Subjects : 63 66 68
	
	
	Roll Number : 1
	
	Marks are : 63 66 68
	
	Total is : 197_

Link this post on your Blog/Website :

Follow us on :   Technoexam on facebook Technoexam on twitter Technoexam on linkedin Technoexam on youtube