Breaking News

Program to calculate the prime factors of a numbers in C

#include
main()
{
int x,n;
printf("Enter a number :");
scanf("%d",&n);
prime_factors(n);
}
int prime_factors(int n)
{
int i=1,k;
while(i<=n)
{
if(n%i==0)
{
k=check_prime(i);
if(k!=0)
printf("%d ",k);
}
i++;
}
}
int check_prime(int n)
{
int i=1;
int c=0;
while(i<=n)
{
if(n%i==0)
c++;
i++;
}
if(c==2)
return n;
else
return 0;
}

No comments