12th Computer Science CBSE JAC

12th Computer Science Important Program

Write a program to check input number is prime or not

#include<iostream.h>
#include<conio.h>
void main()

{
clrscr();
int n,i,j=0;
cout<<"Enter any number=";
cin>>n;
for(i=2;i<n;i++)
{
if(n%i==0)
{
j=1;
break;
}
}
if(j==1)
cout<<"Number is not prime";
else
cout<<"Number is prime";
getch();
}

Output

Enter any number=5
Number is prime

About the author

AIPS

Leave a Comment