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