Dremendo Tag Line

Calculate product and check last digit even or odd in C++

if else - Question 9

In this question, we will see how to input 3 numbers and check if the product of their last digit is even or odd in C++ programming using the if else statement. To know more about if else statement click on the if else statement lesson.

Q9) Write a program in C++ to input 3 numbers and check if the product of their last digit is even or odd.

Program

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

using namespace std;

int main()
{
    int a,b,c,s;
    cout<<"Enter 3 numbers\n";
    cin>>a>>b>>c;
    s=(a%10)*(b%10)*(c%10);
    if(s%2==0)
    {
        cout<<"Product of their last digit is even";
    }
    else
    {
        cout<<"Product of their last digit is odd";
    }
    return 0;
}

Output

Enter 3 numbers
18
32
46
Product of their last digit is even
video-poster