C Program to Find Last Digit of a Number

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Overview

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.

Sharpen Your Fundamentals with Free Learning

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

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

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.

dividing-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

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Conclusion

  • The modulus operator takes two values.
  • We can find the last digit of a given number by taking the modulus with 10.