Read OnLine Cpp Program Example



5 - ARRAY
PRAC 9 PRAC 10
//wap to print addition element
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],i,ans=0;
clrscr();
a[0]=123;
a[1]=43;
a[2]=77;
a[3]=34;
a[4]=67;
for (i=0;i<=4;i++)
{
ans=ans+a[i];
}
cout<<ans;
getch();
}
------output-------
344
//wap to print addition element
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],i,ans=0;
clrscr();
cout<<"Enter array element:";
for (i=0;i<=4;i++)
{
cout<<"\n Enter element:"<<i;
cin>>a[i];
}
for (i=0;i<=4;i++)
{
ans=ans+a[i];
}
cout<<ans;
getch();
}
------output------
Enter array element:
Enter element0:34
Enter element1:54
Enter element2:44
Enter element3:55
Enter element4:45
232
Previous Next
Download Download