HSC Science (Computer Science) 12th Board ExamMaharashtra State Board
Share
Notifications

View all notifications

Write a C++ Program to Accept an Integer Number and Test Whether It is Prime Or Not. - HSC Science (Computer Science) 12th Board Exam - Computer Science 1

Login
Create free account


      Forgot password?

Question

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

Solution

#include 
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" ;
}
  Is there an error in this question or solution?

APPEARS IN

 2017-2018 (March) (with solutions)
Question 5.1.1 | 5.00 marks
Solution Write a C++ Program to Accept an Integer Number and Test Whether It is Prime Or Not. Concept: C++ Programming.
S
View in app×