C The flowchart depicted in Fig 1 prompts the user to enter

C++

The flowchart depicted in Fig. 1 prompts the user to enter two nonnegative integers X and Y and then determines if X is a multiple Y. Write a complete C++ program according to the flowchart.

Solution

Please follow the code and comments for description :

CODE :

#include <iostream> // required header files

using namespace std;

int main() // driver method
{
   int X, Y; // required initialisations
   cout << \"Enter a Non-Negative Integer X : \";// prompt to enter the data
   cin >> X; // getting the data
   cout << \"Enter a Non-Negative Integer Y : \"; // prompt to enter the data
   cin >> Y; // getting the data
  
   if(X == 0) { // check for the null value or zero
       cout << \"X is a multiple of Y.\" << endl; // if so printing the result is a multiple
   } else if(Y == 0) { // check for the null value or zero
       cout << \"X is not a multiple of Y.\" << endl; // if so printing the result is not a multiple
   } else if(X < Y) { // check for the values if the first is less or not
       cout << \"X is not a multiple of Y.\" << endl; // if so printing the result is not a multiple
   } else { // else if the value is greater then the first one
       X = X - Y; // updating the value of X to the subtraction if X from Y
       while(X >= Y) { // iterating for the condition is true
           X = X - Y;
       }
       if(X == 0) { // check for the zero
           cout << \"X is a multiple of Y.\" << endl;// if so printing it is a multiple
       } else {
           cout << \"X is not a multiple of Y.\" << endl; // else printing it is not a multiple
       }
   }
   return 0;
}

OUTPUT :

Case 1 :

Enter a Non-Negative Integer X : 16
Enter a Non-Negative Integer Y : 3
X is not a multiple of Y.

Case 2 :

Enter a Non-Negative Integer X : 10
Enter a Non-Negative Integer Y : 5
X is a multiple of Y.

Hope this is helpful.

C++ The flowchart depicted in Fig. 1 prompts the user to enter two nonnegative integers X and Y and then determines if X is a multiple Y. Write a complete C++ p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site