fork download
  1. #include <stdio.h>
  2. int sum(int n) {
  3. if (n==0)
  4. return 0;
  5.  
  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.  
  16. // your code goes here
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
enter a number : sum from 0 to 32767 is:536854528