+ 1

Sum Game

Print the sum of n values

17th Mar 2017, 3:23 AM
VISHNU H NAIR
VISHNU H NAIR - avatar
4 Respostas
+ 17
I don't get how this is a game... or even a question...
17th Mar 2017, 3:30 AM
Jafca
Jafca - avatar
+ 10
@vishnu declare int a[n]; below cin>>n; Coz after getting n value from user it will assign size for a.
17th Mar 2017, 4:08 AM
Mr.Robot
Mr.Robot - avatar
+ 2
#include<iostream> using namespace std; int main() { int sum=0,n; cout<<"Enter the n value"<<endl; cin>>n; int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; } for(int i=0;i<n;i++) { sum+=a[i]; } cout<<"Sum = "<<sum; return 0; }
17th Mar 2017, 5:17 AM
Jayashankar Swamy
0
#include<iostream> int main() { int sum=0,n; int a[n]; cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; } for(int i=0;i<n;i++) { sum=sum+a[i]; } cout<<"Sum = "<<sum; }
17th Mar 2017, 3:28 AM
VISHNU H NAIR
VISHNU H NAIR - avatar