#include "stdio.h"
#include "conio.h"
long int fib(int); /* Function Prototype */
void main()
{
int n,i;
long int result;
printf("Enter Nth Term : ");
scanf("%d",&n);
i = 0;
while(i < n)
{
result = fib(i++); /* function Call */
printf("%ld\t",result);
}
getch();
}
/* End of Main */
long int fib(int m) /* Function Definition */
{
if (m == 0) /* Control Statements for Recurrsion */
return 0;
else if(m == 1 || m == 2)
return 1;
else
return fib(m-1) + fib(m-2); /* Recursive Statement */
}
/* End of Program */
Saturday, December 5, 2009
FIBONACCI SERIES USING RECURRSION
Labels: Recurrsion
Posted by Unknown at 11:27 PM 0 comments
PROGRAM TO FIND THE SUM OF DIGITS USING RECURRSION
#include "stdio.h"
#include "conio.h"
int sum(long int);/* Function Prototype */
void main()
{
long int num;
int result;
printf("Enter Number :");
scanf("%ld",&num);
result = sum(num); /* Function Call */
printf("Sum of Digits - %d",result);
getch();
}
int sum(long int n) /* Function Definition */
{
int digit;
if(n == 0)
return 0;
else
{
digit = n%10;
return digit + sum(n/10); /* Recursive Statement */
}
}
Labels: Recurrsion
Posted by Unknown at 11:23 PM 0 comments
Subscribe to:
Posts (Atom)