Determines for a pair of integers whether the second is a multiple of the first. - C++ Operator

C++ examples for Operator:Arithmetic Operator

Description

Determines for a pair of integers whether the second is a multiple of the first.

Demo Code

#include <iostream>

bool multiple(int, int);

int main(int argc, const char *argv[]) {
    int x, y, choice = 0;
    while (choice >= 0) {
        std::cout << "Enter two integers (-1 to quit): ";
        std::cin >> x;//from w w w  . ja  va  2 s  . c  o m

        if (x == -1) 
           break;

        std::cin >> y;

        std::cout << x << " and " << y << (multiple(x, y) ? ": true" : ": false") << std::endl;
    }

    return 0;
}
// determines if y is a multiple of x
bool multiple(int x, int y) { 
   return (y % x == 0); 
}

Result


Related Tutorials