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

urgent help in a programming homework question writing a code in C language with

ID: 3566967 • Letter: U

Question

urgent help in a programming homework question writing a code in C language with the description in the picture attached

THANKS ALOT in advance (ps i suck at programming, im trying my best) :')

urgent help in a programming homework question writing a code in C language with the description in the picture attached Description A positive integer greater than 1 is called a prime if it is only divisible by itself and by 1. Write a program that prompts the user to enter an integer between 2 and 1000,000 and prints out whether it is a prime; in case the number is not a prime, it also prints the factorization of the number as a product of primes iii ascending order. Input-Output Example . Enter a positive integer between 2 and 1000000: [11] The number 11 is a prime. . Enter a positive integer between 2 and 1000000: [24] The number 24 is not a prime. 24=2x2x2x3 THANKS ALOT in advance (ps i suck at programming, im trying my best) :')

Explanation / Answer

#include<stdio.h>
#include<math.h>
void primeFactors(int n)
{
// Print the number of 2s that divide n
while (n%2 == 0)
{
printf("%d ", 2);
n = n/2;
}
int i;
// n must be odd at this point. So we can skip one element (Note i = i +2)
for ( i = 3; i <= sqrt(n); i = i+2)
{
// While i divides n, print i and divide n
while (n%i == 0)
{
printf("%d ", i);
n = n/i;
}
}

// This condition is to handle the case whien n is a prime number
// greater than 2
if (n > 2)
printf ("%d ", n);
}

int main(){
int n,i,count=0;
printf("enter a positive integer between 2 and 1000");
scanf("%d",&n);
for(i=1;i<=n;i++){
if((n%i)==0){
continue;
}
else{
count++;

}
}
if(count==2){printf("Enetered number %d is a prime number",n);}
else{
printf("Enetered number %d is not a prime number ",n);
printf("%d=",n);
primeFactors(n);
}
}