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

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

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

Answer :
File Name : c.cpp

#include<stdio.h>
#include<iostream>
using namespace std;

int a, flag=1,i;
int main(){
cout<<"Enter Number : ";
cin>>a;
for(i=2; i<=a/2; ++i){
if(a%i==0){
flag=0;
break;
}
}
if(flag==0){
cout<<a<<" is Not a prime Number"<<endl;
}else{
cout<<a<<" is a prime Number"<<endl;
}
}
Write a C++ program to check whether a given number is prime or not. Write a C++ program to check whether a given number is prime or not. Reviewed by technical_saurabh on May 02, 2021 Rating: 5

No comments:

Powered by Blogger.