Problem Description
Write a C program for Sum of Natural Numbers Using Recursion.CODING ARENA
#include <stdio.h>
int addnum(int n);
int main()
{
int num;
scanf("%d",&num);
printf("%d",addnum(num));
return 0;
}
int addnum(int n)
{
if(n!=0)
return n+addnum(n-1);
else
return n;
}
Test Case 1
Input (stdin)2
Expected Output3
Test Case 2
Input (stdin)3
Expected Output6
Recursion in C
ReplyDelete