fork download
  1.  
  2. #include <stdio.h>
  3. int sum(int n){
  4. if(n==0)
  5. return 0;
  6. else
  7. return n + sum(n-1);
  8. }
  9.  
  10. int main(void) {
  11. int n;
  12. printf("enter a number: ");
  13. scanf("%d",&n);
  14. printf("sum from 0 to %d is:%d\n",n,sum(n));
  15. // your code goes here
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
enter a number: sum from 0 to 32767 is:536854528