Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

prime number program c++

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=2;i<sqrt(n)+1;i++){
        if(n%i==0){
            cout<<"number is not a prime";
            return 0;
        }
    }
    cout<<"number is a prime";
    return 0;
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #prime #number #program
ADD COMMENT
Topic
Name
2+5 =