//5. C Program to find the factors of nth Fibonacci number.
#include<stdio.h>
void main()
{
int num,f1=0,f2=1,f3=0,i;
clrscr();
printf("Enter the value for N:");
scanf("%d",&num);
for(i=1;i<num;i++)
{
f1=f2;
f2=f3;
printf("%d\n",f3); //This statement is for debugging.
f3=f1+f2;
}
printf("\nNth Fibonacci Number = %d \n",f3);
printf("Its factors are:\n");
for(i=1;i<=f3;i++)
{
if(f3%i==0)
printf("%d\n",i);
}
getch();
}
#include<stdio.h>
void main()
{
int num,f1=0,f2=1,f3=0,i;
clrscr();
printf("Enter the value for N:");
scanf("%d",&num);
for(i=1;i<num;i++)
{
f1=f2;
f2=f3;
printf("%d\n",f3); //This statement is for debugging.
f3=f1+f2;
}
printf("\nNth Fibonacci Number = %d \n",f3);
printf("Its factors are:\n");
for(i=1;i<=f3;i++)
{
if(f3%i==0)
printf("%d\n",i);
}
getch();
}
No comments :
Post a Comment