Computer Science, asked by JOYNASKAR, 4 days ago

:Write a C++ program:
WAP to input any two numbers and find the unit digits (Last digit)of both Find out their sum and product. Print the sum and product .[

Answers

Answered by simonsaikia9
2

Program:

#include <iostream>

using namespace std;

int unitDigit(int n)

{

   int unitDG;

   if (n % 10 == 0)

       return n;

   unitDG = n % 10;

   return unitDG;

}

int main()

{

   int n1, n2;

   cout << "Enter the first number" << endl;

   cin >> n1;

   cout << "Enter the second number" << endl;

   cin >> n2;

   cout << "Unit digit of " << n1 << " is " << unitDigit(n1) << endl;

   cout << "Unit digit of " << n2 << " is " << unitDigit(n2) << endl;

   int a = unitDigit(n1), b = unitDigit(n2);

   int sum = a + b;

   int product = a * b;

   cout << "Sum of " << a << " and " << b << " is " << sum << endl;

   cout << "Product of " << a << " and " << b << " is " << product << endl;

   return 0;

}

Similar questions