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

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.