# C Program & Algorithm to check whether the given number is Prime or not

September 11, 2019

This is the C program code and algorithm for checking whether the given number is prime or not.

**Aim:**

Write a C program to check whether the given number is prime or not.

**Algorithm:**

Step 1:StartStep 2:Read numbernStep 3:Set f=0Step 4:For i=2 to n-1Step 5:If n mod 1=0 thenStep 6:Set f=1 and breakStep 7:LoopStep 8:If f=0 then print 'The given number is prime' else print 'The given number is not prime'Step 9:Stop

**Program code**

#include<stdio.h> #include<conio.h> void main( ) { clrscr(); int n,i,f=0; printf("Enter the number: "); scanf("%d",&n); for(i=2;i<n;i++) { if(n%i==0) { f=1; break; } } if(f==0) printf("The given number is prime"); else printf("The given number is not prime"); getch(); }

**Output**

Enter the number : 5 The given number is prime