In this tutorial you will learn about the C program to print Last Digit of Number and its application with practical example.
C Program to print Last Digit of a Number
In this tutorial, we will learn to create a C program that will print the Last Digit of a Number in C programming.
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Arithmetic operations in Ca programming.
- Operators in C programming.
What are the digits in the number?
The number of integers in a number is called its digits. A number is said to be a single-digit number when it is between 0 and 9. Hence, the number is said to be a 4-digit number when it is between the range of 1000 and 9999. In c programming, we can print the first and last digit from the number with the help of a small program.
1. Declaring the variables for the program.
2. Taking the input number from the user.
3. Finding the digits in that given number.
4. Passing those variables to the program.
5. Printing the Last Digit of a Number.
6. Printing the resultant digits to the user.
7. End the program.
Printing the Last Digit of a Number
In this program first, we will take the input number from the user. Then we will separate the digits from that number. And at last, we will print the last digit of the number.
Let us take the example program from the below code for printing the Last Digit of a Number.
//Declaring the required variable for the program.
int n, sum=0, ldigit;
//n = it will hold the input integer value.
//fdigit = it will hold the first integer value.
//ldigit = it will hold the last integer value.
//sum = it will hold the integer value.
//takling the input number from the user.
printf("Enter number = ");
// Finding the last digit of a number
ldigit = n % 10;
//Finding the first digit by dividing n by 10 until n greater then 10
while(n >= 10)
n = n / 10;
//printing the output digit first and the last digit
printf("last digit = %d\n\n", ldigit);
In the above program, we have first initialized the required variable.
- n = it will hold the integer value.
- ldigit = it will hold the integer value.
- sum = it will hold the integer value.
Input Number from the user for the program.
Finding the Last Digit of a Number.
Printing output first and the last digit.