Ask your own question, for FREE!
Computer Science 21 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!
Latest Questions
Breathless: Spooky witch but cute
52 minutes ago 1 Reply 0 Medals
Arriyanalol: help
1 hour ago 7 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
19 hours ago 5 Replies 3 Medals
Jaded012023: Please tell me what you all think of this song
51 minutes ago 6 Replies 1 Medal
Arriyanalol: bro how
46 minutes ago 2 Replies 2 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
19 hours ago 12 Replies 2 Medals
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!