/*Check whether number is Prime or Not*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int number;
cout<<"Enter a number to find whether PRIME or NOT: ";
cin>>number;
for(int i=2; i<number; i++)
{
if((number%i) == 0)
// break;
}
if ((number ==1) || (i==number))
cout<<"\n"<<number<<" is prime";
else
cout<<"\n"<<number<<" is not prime";
getch();
}
For OUTPUT check out the video! :
Click here
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int number;
cout<<"Enter a number to find whether PRIME or NOT: ";
cin>>number;
for(int i=2; i<number; i++)
{
if((number%i) == 0)
// break;
}
if ((number ==1) || (i==number))
cout<<"\n"<<number<<" is prime";
else
cout<<"\n"<<number<<" is not prime";
getch();
}
For OUTPUT check out the video! :
Click here
No comments:
Post a Comment