#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,m=0,flag=0; //declaration of variables.
clrscr(); //It clears the screen.
printf(“Enter the number to check prime:”);
scanf(“%d”,&n);
m=n/2;
for(i=2;i<=m;i++)
{
if(n%i==0)
{
printf(“Number is not prime”);
flag=1;
break; //break keyword used to terminate from the loop.
}
}
if(flag==0)
printf(“Number is prime”);
getch(); //It reads a character from the keyword.
}
Vishalini.R Answered question June 26, 2023
Please enter a positive integer: The number 29 is a prime number. A for loop is iterated from i = 2 to I n/2 in the program. n is not a prime number if it is perfectly divisible by i. The flag is set to 1 in this case, and the loop is terminated with the break statement.
Vishalini.R Answered question June 26, 2023
