Friday, October 14, 2011

Write a function to obtain the prime factors of given number? For example, prime factors of 24 are 2,2,2 and 3, whereas prime factors of 35 are 5 and 7

#include
pri_fact(int n)
{
int i;
for(i=2;i<=n;i++)
{
if(n%i==0)
{
printf("%d ",i);
pri_fact(n/i);
break;
}
}
}
main()
{
int n;
printf("\nEnter an integer :\t");
scanf("%d",&n);
printf("\n");
pri_fact(n);
printf("\n\n");
}

No comments:

Post a Comment