Find unit digit of x raised to power y | C ++ code to find the unit digit of x raised to power y . ; find unit digit ; Get last digit of x ; Last cyclic modular value ; here we simply return the unit digit or the power of a number ; Driver code ; get unit digit number here we pass the unit digit of x and the last cyclicity number that is y % 4
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int unitnumber ( int x , int y ) { x = x % 10 ; if ( y != 0 ) y = y % 4 + 4 ; return ( ( ( int ) ( pow ( x , y ) ) ) % 10 ) ; } int main ( ) { int x = 133 , y = 5 ; cout << unitnumber ( x , y ) ; return 0 ; }