StudyLover
  • Home
  • Study Zone
  • Profiles
  • Contact us
  • Sign in
StudyLover 2. Program to check whether a number is prime.
Download
  1. C++ Programs list
1. Program to find the area and perimeter of a rectangle. : 3. Program to check if a given number is a palindrome.
C++ Programs list

1.      Program to check whether a number is prime.

  1. #include <iostream.h>

  2. #include <conio.h>

  3. int main() {

  4.     int n, i, isPrime = 1;

  5.     cout << "Enter a positive integer: ";

  6.     cin >> n;

  7.     // 0 and 1 are not prime numbers

  8.     if (n == 0 || n == 1) {

  9.         isPrime = 0;

  10.     } else {

  11.         for (i = 2; i <= n/2; ++i) {

  12.             if (n % i == 0) {

  13.                 isPrime = 0;

  14.                 break;

  15.             }

  16.         }

  17.     }

  18.     if (isPrime)

  19.                 cout << n << " is a prime number.\n";

  20.     else

  21.                 cout << n << " is not a prime number.\n";

  22.     getch();

  23.     return 0;

  24. }

1. Program to find the area and perimeter of a rectangle. 3. Program to check if a given number is a palindrome.
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website