c program to find prime factors of a number
#include<stdio.h>
int prime_number(int num);
int main()
{
int num;
printf("\n Enter a number for prime factor");
scanf("%d",&num);
prime_number(num);
}
int prime_number(int num)
{
int i=2;
while(num!=1)
{
if(num%i==0)
{
while(num%i==0)
{
printf("%d\t",i);
num=num/i;
}
}
i++;
}
}
int prime_number(int num);
int main()
{
int num;
printf("\n Enter a number for prime factor");
scanf("%d",&num);
prime_number(num);
}
int prime_number(int num)
{
int i=2;
while(num!=1)
{
if(num%i==0)
{
while(num%i==0)
{
printf("%d\t",i);
num=num/i;
}
}
i++;
}
}
OUT:
Enter a number for prime factor420
2 2 3 5 7
To understand go here https://www.youtube.com/watch?v=Xg89vIL9aog
Comments
Post a Comment