In this post, we will learn how to print the last digit of a given number N using C Programming language.
For example, if we take 425 as input, then this program will find and print the last digit of this number, which is 5 for this case.
So, without further ado, let’s begin this tutorial.
C Program to Print the Last Digit of Given Number N
// C Program to Convert Print the Last Digit of Given Number N #include <stdio.h> int main(){ int num, digit; // Asking for input printf("Enter the digit: "); scanf("%d", &num); digit = num % 10; // Displaying output printf("Last Digit of %d is: %d", num, digit); return 0; }
Output
Enter the digit: 567
Last Digit of 567 is: 7
How Does This Program Work ?
int num, digit;
In this program, we have declared two int data type variables named num and digit.
// Asking for input printf("Enter the digit: "); scanf("%d", &num);
Then, the user is asked to enter a number. The value of this number will get stored in the num named variable.
digit = num % 10;
We find out the last digit of the number by dividing it by 10, this gives us the remainder which is the last digit of the number.
// Displaying output printf("Last Digit of %d is: %d", num, digit);
Finally, the result is displayed on the screen using printf() function.
Conclusion
I hope after going through this post, you understand how to print the last digit of a given number N using C Programming language.
If you have any doubt regarding the topic, feel free to contact us in the comment section. We will be delighted to help you.
Also Read: