To check whether the given no. is prime
(or) not
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i, n, flag = 0;
clrscr();
printf("Enter the Number : ");
scanf("%d", &n);
if(n <= 3)
flag = 0;
else
{
for(i = 2 ; i <= n / 2 ; i++)
if(n % i == 0)
{
flag = 1;
break;
}
}
if(flag == 1)
printf("\nThe number is not prime");
else
printf("\nThe number is prime");
getch();
}
Output:
Case: 1
Enter the Number : 6
The number is not prime
Case: 2
Enter the Number : 11
The number is prime
-
UpdatedDec 30, 2019
-
Views6,944
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order