1 Replies - 1869 Views - Last Post: 25 November 2011 - 07:57 AM

#1 saljanjan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-December 10

can't see the sum of the elements in an array.

Posted 24 November 2011 - 10:03 PM

[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;
}
/]

Is This A Good Question/Topic? 0
  • +

Replies To: can't see the sum of the elements in an array.

#2 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,197
  • Joined: 14-February 08

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/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1