[When I compile the code compiler sits there and does not do anything; i got this code from the net and was expecting that will be able to see the sum.
#include <iostream>
using namespace std;
int main() {
int a[1000]; // Declare an array of 1000 ints
int n = 0; // Number of values in a.
while (cin >> a[n]) {
n++;
}
int sum = 0; // Start the total sum at 0.
for (int i=0; i<n; i++) {
sum = sum + a[i]; // Add the next element to the total
}
cout << sum << endl;
return 0;
}
/]
can't see the sum of the elements in an array.
Page 1 of 11 Replies - 1742 Views - Last Post: 25 November 2011 - 07:57 AM
Replies To: can't see the sum of the elements in an array.
#2
Re: can't see the sum of the elements in an array.
Posted 25 November 2011 - 07:57 AM
Please do not start duplicate topics. You have two in here and on in C++.
Use your original thread in C++.
@Martyr2 - Moved your post to original topic http://www.dreaminco...-in-array-in-c/
Use your original thread in C++.
@Martyr2 - Moved your post to original topic http://www.dreaminco...-in-array-in-c/
Page 1 of 1
|
|

New Topic/Question
This topic is locked


MultiQuote




|