easy
1 views

Print Unit Digit

Extract and print the rightmost digit (units place) of a given integer

Understand the Problem

Problem Statement

Given an integer N, print its unit digit (the digit in the ones place).

The unit digit is the remainder when the number is divided by 10.

Example:
For input 72, the unit digit is 2
For input 65, the unit digit is 5

Constraints

  • The input number N can be any integer (positive, negative, or zero)
  • The unit digit will be a single digit from 0 to 9
  • Standard integer input/output operations apply

Examples

Example 1
Input
72
Output
2
Explanation

72 divided by 10 gives remainder 2, which is the unit digit

Example 2
Input
65
Output
5
Explanation

65 divided by 10 gives remainder 5, which is the unit digit

Example 3
Input
100
Output
0
Explanation

100 divided by 10 gives remainder 0, which is the unit digit

Solution

#include <stdio.h>

int main() {
    int N;
    scanf("%d", &N);
    printf("%d", N % 10);
    return 0;
}
Time:O(1)
Space:O(1)
Approach:

C Solution Explanation:

  1. Include standard input/output header file
  2. Declare integer variable N to store input
  3. Use scanf to read the integer from standard input
  4. Use printf to print N % 10, which gives the unit digit
  5. Return 0 to indicate successful execution

Visual Explanation

Loading diagram...