Program for quotient and remainder of big number | C # 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
using System ; using System . Collections . Generic ; class GFG { static void modBigNumber ( string num , long m ) { List < int > vec = new List < int > ( ) ; long mod = 0 ; for ( int i = 0 ; i < num . Length ; i ++ ) { int digit = num [ i ] - '0' ; mod = mod * 10 + digit ; int quo = ( int ) ( mod / m ) ; vec . Add ( quo ) ; mod = mod % m ; } Console . Write ( " Remainder ▁ : ▁ " + mod + " STRNEWLINE " ) ; Console . Write ( " Quotient ▁ : ▁ " ) ; bool zeroflag = false ; for ( int i = 0 ; i < vec . Count ; i ++ ) { if ( vec [ i ] == 0 && zeroflag == false ) { continue ; } zeroflag = true ; Console . Write ( vec [ i ] ) ; } return ; } public static void Main ( ) { string num = "14598499948265358486" ; long m = 487 ; modBigNumber ( num , m ) ; } }