- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given a string num which is a large number and an integer R. Our task is to create a *program to find remainder when large
number is divided by r in C++*.

**Problem Description** − We need to find the remainder when the number defined by the string is divided by r which is a two-digit number.

**Let’s take an example to understand the problem**

num = “123423450942121” r = 54

7

To find the remainder, we obviously need to divide the number. But dividing huge numbers is a complex process so to ease up the process, we will divide digit by digit. And store the remainder that follows. This process is to be continued for the whole string that contains number from MSB to LSB. And In the end the remainder is printed.

**Program to illustrate the working of our solution**

#include <iostream> #include <string.h> using namespace std; int calcRem(string num, int R){ int currDigit, rem = 0; for (int i = 0; i < num.length(); i++) { currDigit = rem * 10 + (num[i] - '0'); rem = currDigit % R; } return rem; } int main() { string num = "123423450942121"; int R = 54; cout<<"The remainder when large number is divided by r is"<<calcRem(num, R); return 0; }

The remainder when large number is divided by r is 7

- Related Questions & Answers
- Program to find remainder when large number is divided by 11 in C++
- C++ Program to Find Quotient and Remainder
- C/C++ Program to Find reminder of array multiplication divided by n ?
- C/C++ Program to Find the reminder of array multiplication divided by n?
- Divisibility by 12 for a large number in C++ Program
- Find N % (Remainder with 4) for a large value of N in C++
- remainder() in C++ program
- Java Program to find reminder of array multiplication divided by n
- Check if a large number is divisibility by 15 in C++
- Check if a large number is divisible by 20 in C++
- Find reminder of array multiplication divided by n in C++
- C# Program to find whether the Number is Divisible by 2
- Program to find Quotient and Remainder in Java
- PHP program to find the first natural number whose factorial can be divided by a number ‘x’
- C++ Program for quotient and remainder of big number

Advertisements