Advertisement
Cnvmendoza

Prime or Composite for

Oct 28th, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 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.     for (input; num2<=input;){
  8.         //Reset to 0
  9.         two_numbers=0;
  10.         for (num2=1; num2<=input; num2++){
  11.             if (input%num2==0){
  12.                 two_numbers++;
  13.             }
  14.         }
  15.         if (two_numbers==2){
  16.             cout << input << " is a prime number . . .";
  17.         }
  18.         else if (two_numbers!=2 && two_numbers!=0){
  19.             cout << input << " is a composite number . . .";
  20.         }
  21.         else if (two_numbers==0){
  22.             cout << input << " is neither a prime number nor a composite number . . .";
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement