C Program to Find Last Digit of a Number

Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
The last digit of a number in C can be calculated by taking the modulus of a given number by 10, and the operator that is used to find the last of a given number is the "%" operator.
Introduction
Let's suppose you have a number n, and you need to find the last digit of a given number. How you can find it? The most efficient way to find out the last digit of a given number in C language using the modulus operator.
Let's understand what is modulus operator( "%") is. This operator takes two operands, the first operator is the dividend, and the second operand is the divisor and returns the remainder after dividing the dividend by the divisor.
For example, the answer of 10%5 is 0. Because after dividing the 10 by 5, we will get the remainder as 0.
C Program to Find the Last Digit of a Number
Let's understand how to find the last digit of a number using a C program.
Output:
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
C Program to Find the Last Digit of a Number Using Function
Let's understand how to find the last digit of a number using the function in the C language.
In the below program, we are finding the last digit of the given number using the method last digit().
Output:
How Does This Program Work?
If we divide any number by 10, the remainder either will be 0 or in the range [0-9], or also after dividing the number by 10, each digit moves one place to the right to make it 10 times smaller.
In the below image, we are dividing the given number ie. 868 by 10, and the remainder we get after performing this operation is the last digit of the number.

Hence, the remainder of the number after dividing by 10 will be the last digit. If the number is too large that cannot be stored in any kind of datatype even in the long datatype. We will store the number in the String datatype and iterate the String till the end, and get the last digit of the given large number.
Turn Learning into Career Growth
Conclusion
- The modulus operator takes two values.
- We can find the last digit of a given number by taking the modulus with 10.