+ 1
Sum Game
Print the sum of n values
4 Respostas
+ 17
I don't get how this is a game... or even a question...
+ 10
@vishnu declare int a[n]; below cin>>n; Coz after getting n value from user it will assign size for a.
+ 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;
}
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;
}