Last digit of Product of two Large or Small numbers ( a * b ) | C ++ implementation of the above approach ; Fthe unction to print last digit of product a * b ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void lastDigit ( string a , string b ) { int lastDig = ( a [ a . length ( ) - 1 ] - '0' ) * ( b [ b . length ( ) - 1 ] - '0' ) ; cout << lastDig % 10 ; } int main ( ) { string a = "1234567891233" , b = "1234567891233156" ; lastDigit ( a , b ) ; return 0 ; }