Dremendo Tag Line

Input number and print its last digit in C++

cin - Question 4

In this question, we will see how to input a number in C++ programming using the cin statement and print its last digit. To know more about cin statement click on the cin statement lesson.

Q4) Write a program in C++ to input a number and print its last digit.

Number = 245
Last digit = 5

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int n,ld;
    cout<<"Enter a number\n";
    cin>>n;
    ld=n%10;
    cout<<"Last digit="<<ld;
    return 0;
}

Output

Enter a number
483
Last digit=3
video-poster