+ 6
How to create an array of 10 elements & display sum of its elements
3 Answers
+ 6
#include <iostream>
using namespace std;
int main() {
int arr[] = {1,2,3,4,5,6,7,8,9,10};
int total = 0;
for(int i = 0; i < sizeof(arr)/sizeof(arr[0]); ++i) {
total += arr[i];
}
cout << total;
return 0;
}
+ 8
you mean ...from user input?
+ 1
#include<iostream>
using namespace std;
int main()
{
int arr[10],i,total=0;
cout<<"\nEnter any 10 elements : ";
for(i=0;i<10;i++)
{
cin>>arr[i];
}
for(i=0;i<10;i++)
{
total+=a[i];
}
cout<<"\nTotal = "<<total;
return 0;
}