Advertisement
Cnvmendoza

Prime or Composite while

Oct 28th, 2021
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4.     int num2, two_numbers, input;
  5.     cout << "Enter a Number: ";
  6.     cin >> input;
  7.     num2 = 1;
  8.     if (input==0){
  9.         cout << input << " is neither a prime number nor a composite number . . .";
  10.     }
  11.     else if (input!=0){
  12.         while (num2<=input){
  13.             //Reset to 0
  14.             two_numbers=0;
  15.             while (num2<=input){
  16.                 if (input%num2==0){
  17.                     two_numbers++;
  18.                 }
  19.                 num2++;
  20.             }
  21.             if (two_numbers==2){
  22.                 cout << input << " is a prime number . . .";
  23.             }
  24.             else if (two_numbers!=2){
  25.                 cout << input << " is a composite number . . .";
  26.             }
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement