Check Prime Number or Not With Just 1 Click
You're given a number. Will you be able to say if the number is a prime number or not?
Now, check if the number is prime or not with just one click.
No extra efforts wasted.
Given below is a program for a prime number test using C++:
You can however write the code in a different way. This is just a sample.
Open C++
Write the code:
#include <stdio.h>
#include <conio.h>
void main ()
{
int half,x,state,temp;
printf ("Enter the number\n");
scanf ("%d",&x);
half=x/2;
state=1;
temp=2;
while (state!=0&&temp<=half)
{if (x%temp==0)
{state=0;}
else {++temp;}
}
if (state==0)
{printf ("\n%d is not prime\n",x);}
else {printf ("\n%d is prime\n",x);}
}
Run the code.
It works.
To save, use extension .cpp
Thanks!
ConnectU Edu.
TO KNOW MORE OR TO CLARIFY YOUR DOUBTS ON THE TOPIC, PUT A COMMENT.REMARKS, SUGGESTIONS AND QUERIES ARE WELCOME. JUST PUT A COMMENT.
Click here to download the Prime Number Checker Program for FREE
You're given a number. Will you be able to say if the number is a prime number or not?
Now, check if the number is prime or not with just one click.
No extra efforts wasted.
Given below is a program for a prime number test using C++:
You can however write the code in a different way. This is just a sample.
Open C++
Write the code:
#include <stdio.h>
#include <conio.h>
void main ()
{
int half,x,state,temp;
printf ("Enter the number\n");
scanf ("%d",&x);
half=x/2;
state=1;
temp=2;
while (state!=0&&temp<=half)
{if (x%temp==0)
{state=0;}
else {++temp;}
}
if (state==0)
{printf ("\n%d is not prime\n",x);}
else {printf ("\n%d is prime\n",x);}
}
Run the code.
It works.
To save, use extension .cpp
Thanks!
ConnectU Edu.
TO KNOW MORE OR TO CLARIFY YOUR DOUBTS ON THE TOPIC, PUT A COMMENT.REMARKS, SUGGESTIONS AND QUERIES ARE WELCOME. JUST PUT A COMMENT.
Click here to download the Prime Number Checker Program for FREE
No comments:
Post a Comment