Program to find remainder when large number is divided by 11 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 11.

For this we will be provided with an integer. Our task is to find the remainder value when the given value is divided by 11.

Example

 Live Demo

#include <bits/stdc++.h>
using namespace std;
//returning remainder
int remainder(string str) {
   int len = str.length();
   int num, rem = 0;
   for (int i = 0; i < len; i++) {
      num = rem * 10 + (str[i] - '0');
      rem = num % 11;
   }
   return rem;
}
int main() {
   string str = "3435346456547566345436457867978";
   cout << remainder(str);
   return 0;
}

Output

4
raja
Published on 19-May-2020 15:14:17
Advertisements