

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 in C++ Program
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
Example
#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; }
Output
Prime factors of 2632 are :2 2 2 7 47
- Related Questions & Answers
- C Program for Find largest prime factor of a number?
- Python Program for Find largest prime factor of a number
- Java Program to find largest prime factor of a number
- C Program for Find the largest prime factor of a number?
- Prime factor array of a Number in JavaScript
- Find largest prime factor of a number using C++.
- k-th prime factor of a given number in java
- Finding the largest prime factor of a number in JavaScript
- Find sum of a number and its maximum prime factor in C++
- Prime number program in Java.
- Demand Factor, Load Factor, and Diversity Factor
- Pitch Factor, Distribution Factor, and Winding Factor for Harmonic Waveforms
- Java program to check for prime and find next Prime in Java
- Pitch Factor or Coil Span Factor in Alternator
- Count all the numbers less than 10^6 whose minimum prime factor is N C++
Advertisements