Write
a program to calculate to sum of an array of 5 elements.
Before going through program, you should know what is
array. Array is a collection of homogenous elements, consist a common property
and share a common name.
Syntax;
datatype variable name [size];
PROGRAM:
-
#include<stdio.h>
void main ();
{
int a[5], i;
int a[5], i;
Int sum=0 ;
clrscr ( );
for( i=0; i<5; i++ )
{
Printf (“\n enter the number =”);
Scanf(“%d”, & a[i] );
}
for( i=0; i<5; i++);
{
Sum = sum + a[i] ;
}
Printf(“\n sum= %d”, sum);
getch();
}
DRY RUN: -

nice.
ReplyDelete