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

  • برمجة سي بلس بلس
  • برمجة

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

Sample Output:

0
1
1
0

الأجوبة

#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;    
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...