/*wap to find sum of first n terms using recursive function*/ #include<stdio.h> #include<conio.h> int addition(int sum); void main() { int n,sum; clrscr(); printf("enter value of n:"); scanf("%d",&n); sum=addition(n); printf("sum of first %d numbers:%d",n,sum); getch(); } int addition(int n) { int sum=0; if(n==1) { return(1); } else { sum=n+addition(n-1); return(sum); } }
No comments:
Post a Comment