boolean function c++ code example
Example 1: c++ boolean
bool isCodingFun = true;
bool isFishTasty = false;
cout << isCodingFun; // Outputs 1 (true)
cout << isFishTasty; // Outputs 0 (false)
//credit to w3schools.com
Example 2: bool function in c++
bool Divisible(int a, int b) {
return (a % b) == 0;
}
Example 3: bool function in c++
bool Divisible(int a, int b) {
int remainder = a % b; // Calculate the remainder of a and b.
if(remainder == 0) {
return true; //If the remainder is 0, the numbers are divisible.
} else {
return false; // Otherwise, they aren't.
}
}
Example 4: bool function in c++
bool Divisible(int a, int b) {
return !(a % b);
}