Program for quotient and remainder of big number | CPP program to find quotient and remainder when a number is divided by large number represented as string . ; Function to calculate the modulus ; Store the modulus of big number ; Do step by step division ; Update modulo by concatenating current digit . ; Update quotient ; Update mod for next iteration . ; Flag used to remove starting zeros ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; typedef long long ll ; void modBigNumber ( string num , ll m ) { vector < int > vec ; ll mod = 0 ; for ( int i = 0 ; i < num . size ( ) ; i ++ ) { int digit = num [ i ] - '0' ; mod = mod * 10 + digit ; int quo = mod / m ; vec . push_back ( quo ) ; mod = mod % m ; } cout << " Remainder : " ▁ < < ▁ mod ▁ < < ▁ " " cout << " Quotient ▁ : ▁ " ; bool zeroflag = 0 ; for ( int i = 0 ; i < vec . size ( ) ; i ++ ) { if ( vec [ i ] == 0 && zeroflag == 0 ) continue ; zeroflag = 1 ; cout << vec [ i ] ; } return ; } int main ( ) { string num = "14598499948265358486" ; ll m = 487 ; modBigNumber ( num , m ) ; return 0 ; }