Archive for April 2019

Write a program in C++ to check whether the entered number if prime number or not

#include <iostream.h>
#include <conio.h>

int main() {
{  
    int num, i, count = 0;

    cout << "Enter the number to be checked : ";
    cin >> num;

    if (num == 0)
    {
        cout << "\n" << num << " is not prime";
        exit(1);
    }
    else   
    {
        for(i=2; i < num; i++)
            if (num % i == 0)
                count++;
    }
    if (count > 1)
  cout << "\n" << num << " is not prime.";
    else
        cout << "\n" << num << " is prime.";
 return 0;
}


Output:

Read more

Contact Form

Name

Email *

Message *

Followers