Dremendo Tag Line

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

if else - Question 8

In this question, we will see how to input 2 numbers and check if the sum 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.

Q8) Write a program in C++ to input 2 numbers and check if the sum of their last digit is even or odd.

Program

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

using namespace std;

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

Output

Enter 2 numbers
54
69
Sum of their last digit is odd
video-poster