Input number and print its last digit in C
scanf() - Question 4
In this question, we will see how to input a number in C programming using the scanf() function and print its last digit. To know more about scanf() function click on the scanf() function lesson.
Q4) Write a program in C to input a number and print its last digit.
Number = 245
Last digit = 5
Program
#include <stdio.h>
#include <conio.h>
int main()
{
int n,ld;
printf("Enter a number\n");
scanf("%d",&n);
ld=n%10;
printf("Last digit=%d",ld);
return 0;
}
Output
Enter a number 483 Last digit=3