Ask your own question, for FREE!
Computer Science 19 Online
OpenStudy (anonymous):

need help with calculating the sum from 1 to a number inputted by users, and output the sum. For example, if user inputs 3, calculate 1+2+3 and output 6; if user inputs 5, calculate 1+2+3+4+5 and output 15; if user input 10, calculate 1+2+3+4+5+6+7+8+9+10 and output 55.

OpenStudy (bibby):

store the number in a variable and use a loop to sum up until you're done print sum

OpenStudy (anonymous):

here: void main(void) { int i,n,s; printf("type the number: "); scanf("%d",&n); s=n; for(i=1;i<n;i++) { s=s+(n-i); } printf("the sum is: %d ",s); }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!