Programming for Problem Solving (3110003)

BE | Semester-1   Winter-2019 | 07-01-2020

Q3) (c)

Demonstrate a C program to input an integer number and check last digit of number is even or odd.

Program

#include <stdio.h>
void main()
{
    int n, r;
    printf("Enter number: ");
    scanf("%d", &n);
    r=n % 10;
    if(r % 2 == 0)
        printf("Last digit %d is even.\n", r);
    else
        printf("Last digit %d is odd.\n", r);
}

Output:
Enter number: 234
Last digit 4 is even.