Saturday, July 2, 2022

Check if prime

 Check if prime

Problem Statement
Given an integer, print whether that integer is a prime number or not.

c++ code:

#include <bits/stdc++.h> // header file includes every Standard library
using namespace std;


void fun(int n){    
  int i, m=0, flag=0;    
  m=n;  
  for(= 2; i <= sqrt(m); i++)  
  {  
      if(% i == 0)  
      {  
          cout<<"No"<<endl; 
          flag=1;  
          break;  
      }  
  }  
  if (flag==0)  
      cout <<"Yes"<<endl;  
}
int main() {

    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int p;
        cin>>p;
        fun(p);
    }
    return 0;
}

No comments:

Post a Comment

ads vert

Basic HTML Tables - Layout, HTML Tables, Attributes, Aside, Footer, Tr tag, Td tag, Th tag, Tbody

  Basic HTML Tables - Layout, HTML Tables, Attributes, Aside, Footer, Tr tag, Td tag, Th tag, Tbody < table >      < thead >    ...