1/* C Program to print prime factors*/
2
3
4#include<stdio.h>
5void PFactors( int num);
6void IPFactors( int n);
7
8int main( )
9{
10 int num;
11 printf("Enter a number : ");
12 scanf("%d", &num);
13 printf("\nUsing Recursion :: \n");
14 PFactors(num);
15 printf("\n");
16 printf("\nUsing Iteration :: \n");
17 IPFactors(num);
18 printf("\n");
19
20 return 0;
21
22}/*End of main()*/
23
24/*Recursive*/
25
26void PFactors( int num)
27{
28 int i = 2;
29 if( num == 1 )
30 return;
31 while( num%i != 0 )
32 i++;
33 printf("%d ", i);
34 PFactors(num/i);
35}/*End of PFactors()*/
36
37/*Iterative*/
38void IPFactors( int num)
39{
40 int i;
41 for( i = 2; num!=1; i++)
42 while( num%i == 0 )
43 {
44 printf("%d ", i);
45 num = num/i;
46 }
47}/*End of IPFactors()*/
48