English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

The C program for the product and the C of the large number ++Program

Given a very large number, such as num, another very large number, then m. The task is to use division operations to print the quotient, and use the modulus to print the remainder of the large number.

The output should be Remainder = xxx; Quotient = yyy

Assuming we have an input num = string num =" 14598499948265358486", and other input m = 487, then the remainder is430, the quotient is29976385930729688".

Example

Input: num = "214755974562154868"
   m = 17
Output: Remainder = 15
   quotient = 12632704386009109
Input: num ="214"
   m = 5
Output: Remainder = 4
   Quotient = 42

The method we will use to solve the given problem-

  • Initially set mod to 0.

  • Starting from the right, we must use mod to find it: mod = (mod * 10 + digit) % m.

  • Through quo [i] = mod / m find the quotient, where i is the position number of the quotient.

Algorithm

Start
   Step 1 -> Declare long long ll
   Step 2 -> In function void quotientremainder(string num, ll m)
      Declare a vector<int> vec
      Set ll mod = 0
      Loop For i = 0 and i < num.size() and i++
         Set digit = num[i] - '0'
         Set mod = mod * 10 + digit
         Set quo = mod / m
         Call vec.push_back(quo)
         Set mod = mod % m
      End loop
      Print remainder value which is in mod
      Set zeroflag = 0
      Loop For i = 0 and i < vec.size() and i++
         If vec[i] == 0 && zeroflag == 0 then,
            Continue
         End If
         zeroflag = ; 1
         print the value of vec[i]
      End For
      Return
   Step 3 -> In function int main()      Declare and assign num = "14598499948265358486"
      Declare and assign ll m = 487
      Call function quotientremainder(num, m)
Stop

Example

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//Function to calculate modulus
void quotientremainder(string num, ll m) {
   //Store large number modulus
   vector<int> vec;
   ll mod = 0;
   //Perform stepwise division
   for (int i = 0; i < num.size(); i++) {
      int digit = num[i] - '0';
      //Update modulus
      //Current digit.
      mod = mod * 10 + digit;
      //Update quotient
      int quo = mod / m;
      vec.push_back(quo);
      //Update mod for the next iteration.
      mod = mod % m;
   }
   cout << "\nRemainder : " << mod << "\n";
   cout << "Quotient : ";
   //Flag for deleting leading zeros
   bool zeroflag = 0;
   for (int i = 0; i < vec.size(); i++) {
      if (vec[i] == 0 && zeroflag == 0)
         continue;
      zeroflag = ; 1;
      cout << vec[i];
   }
   return;
}
//Main Block
int main() {
   string num = "14598499948265358486";
   ll m = ; 487;
   quotientremainder(num, m);
   return 0;
}

Output Result

Remainder : 430
Quotient : 29976385930729688