How would you approach this exercise, as a beginning programmer? It is a classroom exercise, but I am truly trying to understand the best approach.
How far do you have to go in adding up a sequence of numbers for the sum to exceed 10000?
Print the last number added, and the final sum.
This is what I know to write for a simple adding code. Building off of this, how would you answer the above problem?
#include<iostream>
using namespace std;
int main ()
{
int sum=0;
int n;
for (n=1; n <250; n=n+1)
sum=sum+n;
cout<<"the sum of 1 through 250 is "<<sum<<endl;
return 0;
}
If you just need to find the limiting values then perhaps this will help: