In this section you will learn how to check whether a given number is prime or not. We are performing looping operation on it for checking a number is prime or not.
A number that is divisible only by itself and 1 is called prime number.
2, 3, 5, 7, 11, 13, 17 etc..
#include<stdio.h> #include<conio.h> //PRIME NUMBER PROGRAM void main() { int num,i,p=0; clrscr(); printf("ENTER A NUMBER:- "); scanf("%d",&num); for(i=2;i<=num/2;i++) { if(num%i==0) { p++; break; } } if(p==0 && num!= 1) { printf("%d IS PRIME NUMBER.",num); } else { printf("%d IS NOT A PRIME NUMBER.",num); } getch(); }
ENTER A NUMBER:- 7 7 IS PRIME NUMBER.