The need:
This is a simple program just to get start with recursion explaining the example1 of previous post. This is very specific purpose program. This program finds nth term of a series whose first term is 2 and T(n)=T(n-1) + 1; is given.
The code: ---------------------------------------------------------
#include<stdio.h>
int get_term(int x);
int main()
{
int n,Tn;
printf("Enter which term do you want?\n");
scanf("%d",&n);
Tn=get_term(n);
printf("T(%d) = %d\n",n,Tn);
return 0;
}
int get_term(int x)
{
int term;
if(x==1)
term=2;
else
term= get_term(x-1) + 1;
return term;
}
---------------------------------------------------------
No comments:
Post a Comment
feel free to ask your doubts... if any
you can post your doubts on
www.facebook.com/programsimply