C Program to print the prime factors using recursion

C Programming Language Recursion in c (Article) Recursion in c (Program)

2831

If you don't know what is prime number please read form this tutorial. Prime Number & Prime Factors

Program:

#include<stdio.h>
void PFactors( int num);
void IPFactors( int n);
main( )
{
	int num;
	printf("Enter a number : ");
	scanf("%d", &num);
	PFactors(num); printf("\n");
	IPFactors(num); printf("\n");
}/*End of main()*/

void PFactors( int num)
{
int i = 2;
if( num == 1 )
	return;
	while( num%i != 0 )
	i++;
	printf("%d ", i);
PFactors(num/i);

}/*End of PFactors()*/

/*Iterative*/
void IPFactors( int num)
{
int i;
for( i = 2; num!=1; i++)
	while( num%i == 0 )
	{
	printf("%d ", i);
	num = num/i;
	}
}/*End of IPFactors()*/

Output:

Enter a number : 145
5 29
5 29
Press any key to continue . . .

Explanation:

Program to print the prime factors using recursion

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.