Q:

Write a C++ program to check if two given non-negative integers have the same last digit

-1

Write a C++ program to check if two given non-negative integers have the same last digit

Sample Output:

0
1
1
0

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 x, int y)
        {
            return abs(x % 10) == abs(y % 10);
        }
        
int main() 
 {
  cout << test(123, 456) << endl;  
  cout << test(12, 512) << endl;  
  cout << test(7, 87) << endl;  
  cout << test(12, 45) << 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