7. (B) Write a program to find the sum of a natural number using recursive function
| #include <stdio.h> | |
| int addNumbers(int n); | |
| int main() | |
| { | |
| int n; | |
| printf("Enter a positive integer: "); | |
| scanf("%d", &n); | |
| printf("Sum = %d",addNumbers(n)); | |
| return 0; | |
| } | |
| int addNumbers(int n) | |
| { | |
| if(n!=0) | |
| return n+addNumbers(n-1); | |
| else | |
| return n; | |
| } |
7. (B) Write a program to find the sum of natural number using recursive function
Reviewed by admin
on
December 23, 2019
Rating:
Reviewed by admin
on
December 23, 2019
Rating:

No comments: