A program to initialize a 1-D array and display the sum of the it's elements.

 

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int a[5],i,b=0;

for(i=0;i<5;i++)
{
cout<<"Enter a number:";
cin>>a[i];
}

for(i=0;i<5;i++)
b=b+a[i];

cout<<"\nThe sum of the elements present in array is "<<b;

getch();
}

 

< Back