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

Write a program that asks the user to input a single positive integer (use input

ID: 3864903 • Letter: W

Question

Write a program that asks the user to input a single positive integer (use input validation), then determines whether or not the number is prime. If the integer is prime, print a message saying so. Otherwise, calculate the prime factors of the integer. The program should include a function called is Prime() that takes a single integer as an argument and returns a value indicating whether the number is prime or not and a second function called print Prime Factors() that takes a single integer as an argument and prints the prime factors of that integer. Examples: Enter a positive number: 13 13 is a prime number Enter a positive number: 14 The prime factors of 14 are: 27

Explanation / Answer

#include<stdio.h>

int prime(int);

int primefactor(int);

int main()

{

int res=0,n;

printf(" Enter a Integer Number:");

scanf("%d",&n);

res=prime(n);

if(res==1)

printf(" %d is a Prime Number",n);

else

return (primefactor(n));

}

int prime(int i)

{

int j;

for(j=2;j<=i-1;j++)

{

    if(i%j==0)

      return 0;

}

    if(j==i)

       return 1;

}

  

int primefactor(int n)

{

int i=2;

printf(" The Prime Factors of %d are ",n);

while(n!=1)

{

if(n%i==0)

{

     printf(" %d",i);

}

else

{

    i++;

    continue;

}

    n=n/i;

}

}

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