/* Finding the factor of a number and check whether it is prime or not */
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
int n,i,r,flag=0;
printf("Enter a number:");
scanf("%d",&n);
for(i=2;i<n;i++)
{
r=n%i;
if(r==0)
{
flag=1;
printf("%d is the factor of %d\n",i,n);
}
}
if(flag==1)
{
printf("The number is not prime.\n");
}
else
{
printf("The number is prime.\n");
}
return(0);
}
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
int n,i,r,flag=0;
printf("Enter a number:");
scanf("%d",&n);
for(i=2;i<n;i++)
{
r=n%i;
if(r==0)
{
flag=1;
printf("%d is the factor of %d\n",i,n);
}
}
if(flag==1)
{
printf("The number is not prime.\n");
}
else
{
printf("The number is prime.\n");
}
return(0);
}
Comments
Post a Comment