 # Prime Factors in C++

Subject Computer Science C-Family Programming

## Question

The prime factors of a number are all of the prime numbers that can be multiplied together to get the number.
Examples:
8=1*2*2*2
3=1*3
10=1*2*5
24=1*2*2*2*3
Your program should find the prime factors recursively. Find the first factor by trying the divisors
2,3,5,7,11,13, 15 (15 won't work because we already tried 3 and 5, but it is easier to count by 2's) . If no divisor works up to the square root, then the number is prime.
Lets see how we got the results for 24.
The user entered 24 and we printed "24=1*"
We call factors(24). In factors(24) we find the divisor 2 and print "2*" and then call factors(12).
In factors(12) we find the divisor 2 and print "2*" and then call factors(6).
In factors(6) we find the divisor 2 and print "2*" and then call factors(3).
In factors(3) we cannot find a divisor so we print "3" and end.

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <iostream>

using namespace std;

void primeFactors(int num);

int main()
{
int num;

cout << "Please enter in the number that we want to find the prime factors of: ";
cin >> num;
cout << "Factors of " << num << " = ";
primeFactors(num);
cout << "\n";
return 0;
}

void primeFactors(int num)
{
int factor = 2;

while(true)
{...

This is only a preview of the solution. Please use the purchase button to see the entire solution

## Related Homework Solutions

Delivery Truck Program in C \$75.00
Programming
Computer Science
C Language
Delivery Truck
Features
Pointers
Variables
Functions
Loops
Jobs
Sorting
Printing
Information
Loops
Statements
Data
Input
Output
Programming Problem: Skyline Buildings \$8.00
Programming
C++
Skyline Buildings
Computer Science
Codes
XOR
Algorithms
Implementations
Languages
Classes
Area
Maximum Values
Corresponding Elements
Constraints
Statements
Variables
Moon Weight Calculation, How Many Calories, and Word Game in C++ Language \$20.00
Computer Science
C-Family Programming
Moon
Weight
Calculation
Calories
Word
Game
C++
Gravity
Moon.cpp
Servings
Plays
Name
City
College
Pet
Wordgame.cpp
Tic Tac Toe Using C Programming Language \$35.00
Computer Science
C
Algorithms
Tic Tac Toe
Games
Board
Rules
Players
Loops
Characters
Combinations
Statements
Variables
Superhero Fight in C++ \$35.00
Programming
Classes
Vectors
Operators
Pointers
Computer Science
Superhero Fight
Game Developments
C++
OOP
Powers
Drivers
Lasers
Strength
Variables
Loops
Statements
Interfaces
Strings
Integers
Random Functions
Input
Output
Number Conversion to Any Base \$18.00
Base Conversion