Program to find remainder when large number is divided by r in C++

C++Server Side ProgrammingProgramming

In this tutorial, we will be discussing a program to find remainder when a large number is divided by r.

For this we will be provided with a large integer. Our task is to find the remainder value when that large integer is divided by given value r.


 Live Demo

#include <bits/stdc++.h>
using namespace std;
//returning remainder
int Remainder(string str, int R) {
   int len = str.length();
   int Num, Rem = 0;
   for (int i = 0; i < len; i++) {
      Num = Rem * 10 + (str[i] - '0');
      Rem = Num % R;
   return Rem;
int main() {
   string str = "13589234356546756";
   int R = 13;
   cout << Remainder(str, R);
   return 0;


Published on 19-May-2020 15:16:02