31.1k views
1 vote
Return true if the given non-negative number is a multiple of 3 or 5, but not both. Use the % "mod" operator.

User Azikiwe
by
7.6k points

1 Answer

4 votes

the following C++ function will return true if the given non - negative number is multiple of 5 or 3 else it will return false.

bool function( int x ){

// variable to check if it is multiple of both or not

int number =0;

if(3%x == 0){

number++;

}

if(5%x == 0){

number++;

}

// Now returning by deciding

if( number <=1)

return true;

else

return false

}

User Flagoworld
by
8.6k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.