How to compute mod of a big number ? | C ++ program to compute mod of a big number represented as string ; Function to compute num ( mod a ) ; Initialize result ; One by one process all digits of ' num ' ; Driver program
#include <iostream> NEW_LINE using namespace std ; int mod ( string num , int a ) { int res = 0 ; for ( int i = 0 ; i < num . length ( ) ; i ++ ) res = ( res * 10 + ( int ) num [ i ] - '0' ) % a ; return res ; } int main ( ) { string num = "12316767678678" ; cout << mod ( num , 10 ) ; return 0 ; }