- Related Questions & Answers
- C Program for Tower of Hanoi
- C++ Program for Dijkstra’s shortest path algorithm?
- C/C++ Program for nth Catalan Number?
- C Program to Multiply two Floating Point Numbers?
- C program to find the length of a string?
- C Program to Check if all digits of a number divide it
- C Program to Check if a Given String is a Palindrome?
- Write a program to Delete a Tree in C programming
- Write a C program to print “ Tutorials Point ” without using a semicolon
- Super Prime in c programming
- Sum of the nodes of a Singly Linked List in C Program
- Sum of first n natural numbers in C Program
- C Program for simple interest?
- Area of a n-sided regular polygon with given Radius in C Program?
- Area of a leaf inside a square in C Program?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

**Prime Factor** is a prime number which is the factor of the given number.

**Factor of a number** are the numbers that are multiplied to get the given number.

**Prime Factorisation** is the process of recursively dividing the number with its prime factors to find all the prime factors of the number.

Example : N = 120 Prime factors = 2 5 3 Factorization : 2 * 2 * 2 * 3 * 5

Some points to remember about prime factors of a number

- Set of prime factors of a number is unique.
- Factorization is important in many mathematical calculations like divisibility, finding common denominators, etc.
- It’s an important concept in cryptography.

Program to find prime factors of a number

#include <iostream> #include <math.h> using namespace std; void printPrimeFactors(int n) { while (n%2 == 0){ cout<<"2\t"; n = n/2; } for (int i = 3; i <= sqrt(n); i = i+2){ while (n%i == 0){ cout<<i<<"\t"; n = n/i; } } if (n > 2) cout<<n<<"\t"; } int main() { int n = 2632; cout<<"Prime factors of "<<n<<" are :\t"; printPrimeFactors(n); return 0; }

Prime factors of 2632 are :2 2 2 7 47

Advertisements