Write a C program to find whether a given number is Prime nu
Solution
/*program for prime number * /
# include < stdio.h >
# include < conio.h>
void main ( )
{
int i , n , flag =0 ;
clrscr();
printf (\" enter the positive integer \" ) ;
scanf(\"%d\", & n);
for ( i=2 ; i<=n/2 ; i++)
{
if ( n%i==0)
{
flag =1;
break;
}
}
if ( flag==0)
printf( \"%d is a prime number \", n);
else
printf( \" %d is not a prime number \" , n);
return 0;
}
o/p
enter the positive integer : 17
17 is a prime number .
/* program for fibonacci number * /
# include < stdio.h>
# include < conio.h >
void main()
{
int n,a,b,c,d;
clrscr();
printf ( \" enter the number \");
scanf ( \" %d \" , & n) ;
a=5*n*n+4;
b=5*n*n-4;
c= sqrt(a);
d=sqrt(b);
if ( ( c*c==a)||( d*d==b))
printf( \" the given no is a fibonacci number \");
else
printf ( \" the given no is not a fibonacci no\");
getch();
}
o/p
enter the number 5
the given no is a fibonacci number

