Home » C program to find prime factors of a number using recursion

C program to find prime factors of a number using recursion

Learn about C program to find prime factors of a number using recursion techniques in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Contents

C program to find prime factors of a number using recursion

Program:

#include<stdio.h>

int primeFactor(int num)
{
   int i = 2;
   if(num==1) return;
   while(num%i!=0) i++;
   printf("%d\t",i);
   primeFactor(num/i);
}

int main()
{
   int number;

   printf("Enter a Positive Integer number: ");
   scanf("%d",&number);

   printf("Prime factors of %d :\n",number);
   primeFactor(number);

   return 0;
}

Output:

Enter a Positive Integer number: 12
Prime factors of 12 :
2 2 3

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C program to convert a positive decimal number to binary, octal, and hexadecimal number using recursion techniques
C program to find the sum of digits in a number using recursion