Thursday, December 14, 2017

C++ Without using operators (/, *, %) and only using [if, else if, while loop, do... while] find divisible of a and b. Otherwise, state "not divisible!


#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    int a, b, quotient = 0;
        cin >> a >> b;

    if (b > a)
    {
        cout << "Not divisible!";
    }

    else
    {
        while (a >= b)
        {
           a -= b;
           quotient++;
        }

        cout << "Divisible!" << endl;
        cout << "Quotient: " << quotient << "\tRemainder: " << a << endl;
    }

    return 0;
}

No comments:

Post a Comment