Program that checks whether a number is prime or not by using if else structure and while loop

Program that checks whether a number is prime or not.

Program that checks whether a number is prime or not by using if else structure and while loop

Object: Write a program that checks whether a number is prime or not by using if else structure and while loop. C++ projects for beginners with source code

Code:

#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int num, i=2, a=0;
cout<<“Enter any Number: “;
cin>>num;
while(i <= num/2)
{
if(num%i == 0)
{
a=1;
break;
}
i++;
}
if(a == 0)

cout<<num<<” is a Prime Number.\n”;
else

cout<<num<<” is Not a Prime Number.\n”;
getch();
}

Output:

Program that checks whether a number is prime or not by using if else structure and while loop

Program that checks whether a number is prime or not by using if else structure and while loop

M.A Siddiqui

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

1 Response

  1. ownecahzqd says:

    Muchas gracias. ?Como puedo iniciar sesion?

Leave a Reply

Your email address will not be published. Required fields are marked *