Q:

Write a C++ program to check if a given number is within 2 of a multiple of 10

0

Write a C++ program to check if a given number is within 2 of a multiple of 10

Sample Output:

0
0
1
1

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
 
using namespace std;

bool test(int n)
        {
             return n % 10 <= 2 || n % 10 >= 8;
        }
     
        
int main() 
 {
  cout << test(3) << endl; 
  cout << test(7) << endl; 
  cout << test(8) << endl;
  cout << test(21) << endl;         
  return 0;      
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now