Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. Any integer above 1 is either a prime number, or can be made by multiplying p

ID: 3904723 • Letter: 5

Question

5. Any integer above 1 is either a prime number, or can be made by multiplying prime numbers together. For example: 16 2 x 2 x 2 x 2- (244) 17 (171) 18-2x 3 x 3- (21) x (342) Write a C program, primeFactor.c, that asks the user for an integer number greater than 1 and displays the product of its prime factors. You program should implement at least the 1) int readNum () to take a valid number (greater than 1) from the user. This function IsPrime (int prime) to check if a number is a prime. This function has one 3) int findPrimeCount (int num, int prime) to count the number of a given following 3 functions has no input and returns a valid integer number entered by the user. bool integer variable as an input and a boolean variable as an output, named p_flag 2) prime in the input number and display the result in the format of (prime freq). This function has two integer variables of num and prime as an input and returns the updated. For example, calling findPrimeCount (12,2) displays (22) and returns the updated number of 3. A Sample interaction is as follow: Enter a valid number (1 18 18 1 x (2A1) x (3A2) Enter a valid number (1) Invalid number. Enter a valid number (>1): 19 19 1x(1941)

Explanation / Answer

Below is your code.Please do rate this answer positive, If i was able to help you. Let me know if you have any issues in comments

#include<stdio.h>

#include<stdbool.h>

#include<math.h>

int readNum(int num)

{

if (num <= 1)

{

printf("Invalid Number.");

return -1;

}

else

{

printf("%i = ", num);

return num;

}

}

int pcount = 0;

bool isPrime(int prime)

{

bool p_flag = false;

int i;

for(i = 2; i < prime; i++)

{

if(prime % i == 0)

{

pcount += 1;

}

}

if (pcount > 0)

{

p_flag = false;

}

else if (pcount == 0)

{

p_flag = true;

}

return p_flag;

}

int findPrimeCount(int num, int prime)

{

int freq = 1;

printf("1 ");

for(prime = 2; prime < num; prime++)

{

freq = 1;

while((num % prime) == 0)

{

num = num / prime;

freq++;

}

  

freq--;

  

if(freq > 0)

{

printf(" x (%i ^ %i)", prime, freq);

}

}

if(num != 1)

{

printf(" x (%i ^ 1)", num);

}

return num;

}

int main(void)

{

int number = 0;

printf("Enter a valid number (>1): ");

scanf("%i", &number);

int n = readNum(number);

if(n != -1) {

if(isPrime(number) == 1)

{

printf("1 x (%i ^ 1)", number);

}

else if (isPrime(number) == 0)

{

findPrimeCount(number, 2);

}

}

  

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote