Trending This Week:

test

Post Top Ad

Your Ad Spot

Thursday, June 9, 2022

C++ program to check whether the number is prime or not using squreroot

 






C++ program to check whether the number is prime or not using squreroot


#include <bits/stdc++.h>

using namespace std;

int main()

{

    int n;

    cout<< "enter Number : ";

    cin>>n;

    int flag=1;

    for(int i=2;i*i<=n;i++)

    {

        if(n%i==0)

        {

            flag=0;

            break;

        }

    }

    if(flag)

        cout<<"Given number is a prime number"<<endl;

    else

        cout<<"Given number is not a prime number"<<endl;

    return 0;

}


No comments:

Post a Comment

Post Top Ad

Your Ad Spot