Friday, June 13, 2008

Find out if number is prime or not

/*Write a Prog. to know if a number is prime or not */

/*Henceforth I am using GCC compiler of Linux ( Fedora Core 9 & RHEL-5 for compilation prev. I used Visual Studio Express 2008 for compilation */

#include < stdio.h >
int main(void)
{
int i,m = 1 ;
printf("Enter a number to know if its prime or composite : ");
scanf("%d",&i);
while ( m <= i)
{
if ((i % m) == 0)
printf("%d is prime factor of %d\n",m,i);
m = m++;
}
return 0;
}

No comments: