C++ Program to find the Last Digit of a Number

Write a C++ Program to find the Last Digit of a Number with an example. Any number percentage ten will give the last digit of that number, and in this C++ program, we used the same.

#include<iostream>

using namespace std;

int main()
{
	int number, lastDigit;
	
	cout << "\nPlease Enter Any Number to find Last Digit =  ";
	cin >> number;
  	
  	lastDigit = number % 10;
  	
	cout << "\nThe Last Digit in a Given Number " << number << " = " << lastDigit; 
		
 	return 0;
}
Please Enter Any Number to find Last Digit =  5789

The Last Digit in a Given Number 5789 = 9

C++ Program to find the Last Digit of a Number using Functions

#include<iostream>

using namespace std;

int lastDigitofNumber(int num)
{
	return num % 10;
}

int main()
{
	int number, lastDigit;
	
	cout << "\nPlease Enter Any Number to find Last Digit =  ";
	cin >> number;
  	
  	lastDigit = lastDigitofNumber(number);
  	
	cout << "\nThe Last Digit in a Given Number " << number << " = " << lastDigit; 
		
 	return 0;
}
C++ Program to find the Last Digit of a Number 2