Advertisement
Cnvmendoza

Prime or Composite do while

Oct 28th, 2021
161
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.     num2=1;
  8.     do{
  9.         //Reset to 0
  10.         two_numbers=0;
  11.         if(input==0){
  12.             cout << input << " is neither a prime number nor a composite number . . .";
  13.         }
  14.         else if(input!=0){
  15.             do{
  16.                 if (input%num2==0){
  17.                     two_numbers++;
  18.                 }
  19.                 num2++;
  20.             }while(num2<=input);
  21.         }
  22.     }while (num2<=input);
  23.     if (two_numbers==2){
  24.         cout << input << " is a prime number . . .";
  25.     }
  26.     else if (two_numbers!=2){
  27.         cout << input << " is a composite number . . .";
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement