Tuesday, September 15, 2015

Filled Under:

C program to check whether a number is prime and to display Fibonacci series up to the given prime number

Share
#include<stdio.h>
#include<conio.h>
void main()
{
 int num,flag=0,i,j,a=0,b=1,c;
clrscr();
printf("Enter the number:\n");
scannf("%d",&num);
if(num==1)
{
printf("1 is neither prime nor composite");
getch();
exit(0);
}
else
{
for(i=2;i<num;i++)
if(num%i==0)
flag++;
}
if(flag>0)
printf("Number is not prime");
else
{
printf("Number is prime\nFibonacci series is:\n%d\t%d\t",a,b);
for(j=2;j<num;j++)
{
c=a+b;
printf("%d\t",c);
a=b;
b=c;
}
}
getch();
}

0 comments:

Post a Comment