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

PLEASE TYPE CODE IN C AND ALLOW IT TO COPY AND PASTE PLEASE! 3) Write a program

ID: 3585039 • Letter: P

Question

PLEASE TYPE CODE IN C AND ALLOW IT TO COPY AND PASTE PLEASE!

3) Write a program that indicates if a number input is a prime number or not. The program should repeat this until the user enters O to exit. For example, the input of 17 should print "prime", since 17 has no divisors other than 17 and 1 (hence 17 is a prime number) Input of 21 should print "not a prime" (3 and 7 are both divisors of 21, hence 21 is not a prime number) Run the program using your own Red ID number to determine if it is a prime number

Explanation / Answer

#include <stdio.h>
#include<conio.h>

void main()
{
    int n, i, flag = 0;

    printf("Enter a positive integer number");
    scanf("%d",&n);

    for(i=2; i<=n/2; ++i)
    {
              
        if(n%i==0)   // condition for checking a nonprime number
        {
            flag=1;
            break;
        }
    }

    if (flag==0)
        printf("%d is a prime number.",n);
    else
        printf("%d is not a prime number.",n);
  
    getch();
}

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