एडब्लॉकर मिला (Adblocker Detected)!

नमस्ते! aasansolution.in को पढ़ने के लिए कृपया अपना एडब्लॉकर या Brave Shield को बंद करें।

हमारी मुफ्त सेवाओं को जारी रखने के लिए विज्ञापनों की अनुमति देना ज़रूरी है।

मैंने इसे बंद कर दिया है - रिफ्रेश करें

Thursday, 5 May 2022

Question:- Write a program in c++ to check the entered number by the user is prime or not.

Prime number is a number that is greater than 1 and divided by 1 or itself.  2, 3, 5, 7, 11, 13, 17, 19, 23.... are the prime numbers.

ऐसी संख्‍याएं जो केवल 1 व स्‍वयं से ही विभाजित होती है भाज्‍य संख्‍या कहलाती हैं। जैसे  2, 3, 5, 7, 11, 13, 17, 19, 23....


#include <iostream>  

using namespace std;  

int main()  

{  

  int n, i, m=0, flag=0;  

  cout << "Enter the Number to check Prime: ";  

  cin >> n;  

  m=n/2;  

  for(i = 2; i <= m; i++)  

  {  

      if(n % i == 0)  

      {  

          cout<<"Number is not Prime."<<endl;  

          flag=1;  

          break;  

      }  

  }  

  if (flag==0)  

      cout << "Number is Prime."<<endl;  

  return 0;  

}  


Output:

Enter the Number to check Prime: 17  

Number is Prime.   

Enter the Number to check Prime: 57 

Number is not Prime.


No comments:

Post a Comment