Determining if a number is prime

后端 未结 20 1333
悲哀的现实
悲哀的现实 2020-11-30 03:05

I have perused a lot of code on this topic, but most of them produce the numbers that are prime all the way up to the input number. However, I need code which only checks w

20条回答
  •  Happy的楠姐
    2020-11-30 03:09

    //simple function to determine if a number is a prime number
    //to state if it is a prime number
    
    
    #include 
    
    using namespace std;
    
    
    int isPrime(int x);  //functioned defined after int main()
    
    
    int main()
    {
     int y;
        cout<<"enter value"<>y;
    
        isPrime(y);    
    
      return 0;
    
     } //end of main function
    
    
    //-------------function
    
      int isPrime(int x)
     {
       int counter =0;
         cout<<"factors of "<2) 
         { 
          cout<<"value is not a prime number"<<"\n\n";
         }
    
      if(counter<=2)
         {
           cout<<"value is a prime number"<

提交回复
热议问题