A Simple Program Using One - dimensional Array
A one dimensional array is used when it is necessary to keep a large number of items in memory and reference all the items in a uniform manner.Write a program to find average marks obtained by a class of 30 students in a test:
#include<stdio.h>
void main( )
{
int avg, sum = 0 ;
int i ; int marks[30] ; /* array declaration */
for ( i = 0 ; i <= 29 ; i++ )
{
printf ( “\nEnter marks “ ) ;
scanf ( “%d”, &marks[i] ) ; /* store data in array */
}
for ( i = 0 ; i <= 29 ; i++ )
sum = sum + marks[i] ; /* read data from an array*/
avg = sum / 30 ;
printf ( “\nAverage marks = %d”, avg ) ;
}
No comments:
Post a Comment