Question & Answer: Write an interactive program that will read in a positive integer value and determine if the integer is a prime number……

In C:

Question & Answer: Write an interactive program that will read in a positive integer value and determine if the integer is a prime number...... 1

Write an interactive program that will read in a positive integer value and determine if the integer is a prime number.

Expert Answer

 

int main() {

printf(“Enter any integer: “);

int n,i;

scanf(“%d”, &n); //reading the input

n=12;

if(n>=0){

printf(“%d is a positive integer.n”, n); //prints positive integer

//code prime numbers

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

{

if(n%i==0){

break;

}

}

if(i==n)

{

printf(“%d is a prime number.n”, n);

}

else

{

printf(“%d is not a prime no.n”, n);

}

}

else

{

printf(“%d is a negative integer.n”, n);

}

}

Still stressed from student homework?
Get quality assistance from academic writers!