The Program in C++to Check if two given non-negative integers have Same last digit is given below:
#include <iostream>
using namespace std;
int main() {
int num1, num2;
cout <<"Hello Codeauri Family, Enter the integers here:\n";
cin>>num1>>num2;
int lastDigit1 = num1 % 10;
int lastDigit2 = num2 % 10;
if (lastDigit1 == lastDigit2) {
cout << "The two integers have the same last digit." << endl;
} else {
cout << "The two integers do not have the same last digit." << endl;
}
return 0;
}
Output:
Hello Codeauri Family, Enter the integers here:
1099
9099
The two integers have the same last digit.
Or
Hello Codeauri Family, Enter the integers here:
9087
4590
The two integers do not have the same last digit.
Pro-Tips💡
This program prompts the user to enter two non-negative integers, then it finds the last digit of each integer by using the modulo operator (%).
Finally, it compares the last digits of the two integers using an if statement and prints out the appropriate message based on the result.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.