Here we are taking 6 integers using the loop. First we Prompt user to input 6 integer and take loop for it. We have defined 'i' as integer globally and first 6 loop of input is run and after that again another 6 loop is run for addition purpose where;
sum+=a[i]; this statement ads each value starting from 1 to 6.
/*Write program to take 6 integers form user and display thier sum*/
#include<iostream>
using namespace std;
int main(){
int a[6],i;
cout<<"Enter 6 integer";
for(i=0; i<6; i++){
cin>>a[i];
}
int sum=0;
for(i=0; i<6; i++){
sum +=a[i];
}
cout<<sum;
return 0;}

0 Comments had been done yet:
Post a Comment