fork download
  1. #include <stdio.h>
  2. int sum( int n){
  3. if (n==0|| n==1) return n;
  4. else return n+sum(n-1);
  5. }
  6.  
  7. int main(void) {
  8. int n;
  9. printf("Enter the value of n: \n");
  10. scanf("%d",&n);
  11. int x = sum(n);
  12. printf("%d",x);
  13. return 0;
  14. }
Success #stdin #stdout 0s 5320KB
stdin
5
stdout
Enter the value of n: 
15