मराठी
महाराष्ट्र राज्य शिक्षण मंडळएचएससी विज्ञान (संगणक विज्ञान) इयत्ता १२ वी

Write a C++ program to accept an integer number and test whether it is prime or not. - Computer Science 1

Advertisements
Advertisements

प्रश्न

Write a C++ program to accept an integer number and test whether it is prime or not.

Write C++ program to read any integer and then check whether it’s prime or not prime no.

कोड लेखन
Advertisements

उत्तर

C++ program to test whether the inputted number is prime or not.

#include <iostream.h>
void main() 
{
      int prime, C = 0;
      cout << "Enter the number";
      cin >> prime;
      for (int i = 2; i < prime; i++) 
   {
      if (prime % i == 0)
          C = 1;
   }
   if (C == 0)
      cout << "The number" << prime << "is prime number";
   else
      cout << "The number" << prime << "is not a prime number";
}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2017-2018 (March)
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×