+ 3

How do you this in code? Exercise 2: I will give you a number n. S = 1+2+3+...+n . Then print S

I'm a beginner and barely learning anything. My teacher is already giving me hard questions. lol. But sometimes I don't know what he is talking about and it confuses me. Thank you all for responding. Namaste

1st Oct 2018, 6:08 AM
Kittyky.n
Kittyky.n - avatar
4 Réponses
+ 19
#include <stdio.h> int main() { int a,b=1; scanf("%d",&a); start: printf("%d",b); if(--a>b) { b+=a; goto start; } return 0; }
1st Oct 2018, 6:38 AM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 4
I just wrote this code for someone else about two hours ago: https://code.sololearn.com/csfXuMdCM4AU/?ref=app
1st Oct 2018, 6:26 AM
Aleksander Szczepura
Aleksander Szczepura - avatar
0
i have written a code for you based on recursion https://code.sololearn.com/csaGm8t5IkY5/?ref=app
1st Oct 2018, 12:16 PM
Prince Verma
Prince Verma - avatar
0
main() {int n,i; scanf("%d",&n); for (i=0;i<n;i++); printf("sum=%d",i); }
9th Oct 2018, 1:43 PM
Prabakar
Prabakar - avatar