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