# Program to find remainder when large number is divided by 11

Given a number n, the task is to find the remainder when n is divided by 11. The input of number may be very large.

Examples:

```Input : str = 13589234356546756
Output : 6

Input : str = 3435346456547566345436457867978
Output : 4
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Since the given number can be very large, we can not use n % 11. There are some steps that needs to be used to find remainder:

```1. Store number in string.
2. Count length of number string.
3. Convert string character one by one
into digit and check if it's less than
11. Then continue for next character
otherwise take remainder and use
remainder for next number.
4. We get remainder.

Ex. str = "1345"
len = 4
rem = 3
```

## C++

 `// CPP implementation to find remainder ` `// when a large number is divided by 11 ` `#include ` `using` `namespace` `std; ` ` `  `// Function to return remainder ` `int` `remainder(string str) ` `{ ` `    ``// len is variable to store the ` `    ``// length of number string. ` `    ``int` `len = str.length(); ` ` `  `    ``int` `num, rem = 0; ` ` `  `    ``// loop that find remainder ` `    ``for` `(``int` `i = 0; i < len; i++) { ` `        ``num = rem * 10 + (str[i] - ``'0'``); ` `        ``rem = num % 11; ` `    ``} ` ` `  `    ``return` `rem; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``string str = ``"3435346456547566345436457867978"``; ` `    ``cout << remainder(str); ` `    ``return` `0; ` `} `

## Java

 `// JAVA implementation to find remainder ` `// when a large number is divided by 11 ` `import` `java.io.*; ` ` `  `class` `GFG{ ` `     `  `    ``// Function to return remainder ` `    ``static` `int` `remainder(String str) ` `    ``{ ` `        ``// len is variable to store the ` `        ``// length of number string. ` `        ``int` `len = str.length(); ` `      `  `        ``int` `num, rem = ``0``; ` `      `  `        ``// loop that find remainder ` `        ``for` `(``int` `i = ``0``; i < len; i++) { ` `            ``num = rem * ``10` `+ (str.charAt(i) - ``'0'``); ` `            ``rem = num % ``11``; ` `        ``} ` `      `  `        ``return` `rem; ` `    ``} ` `      `  `    ``// Driver code ` `    ``public` `static` `void` `main(String args[]) ` `    ``{ ` `        ``String str = ``"3435346456547566345436457867978"``; ` `        ``System.out.println(remainder(str)); ` `    ``} ` `} ` ` `  `/*This code is contributed by Nikita Tiwari.*/`

## Python3

 `# Python 3 implementation to find remainder ` `# when a large number is divided by 11 ` ` `  `# Function to return remainder ` `def` `remainder(st) : ` `     `  `    ``# len is variable to store the ` `    ``# length of number string. ` `    ``ln ``=` `len``(st) ` `     `  `    ``rem ``=` `0` `     `  `    ``# loop that find remainder ` `    ``for` `i ``in` `range``(``0``, ln) : ` `        ``num ``=` `rem ``*` `10` `+` `(``int``)(st[i]) ` `        ``rem ``=` `num ``%` `11` `         `  `    ``return` `rem ` `     `  `     `  `# Driver code ` `st ``=` `"3435346456547566345436457867978"` `print``(remainder(st)) ` ` `  ` `  `# This code is contributed by Nikita Tiwari. `

## C#

 `// C# implementation to find remainder ` `// when a large number is divided by 11 ` `using` `System; ` ` `  `class` `GFG ` `{ ` `     `  `    ``// Function to return remainder ` `    ``static` `int` `remainder(``string` `str) ` `    ``{ ` `         `  `        ``// len is variable to store the ` `        ``// length of number string. ` `        ``int` `len = str.Length; ` `     `  `        ``int` `num, rem = 0; ` `     `  `        ``// loop that find remainder ` `        ``for` `(``int` `i = 0; i < len; i++)  ` `        ``{ ` `            ``num = rem * 10 + (str[i] - ``'0'``); ` `            ``rem = num % 11; ` `        ``} ` `     `  `        ``return` `rem; ` `    ``} ` `     `  `    ``// Driver code ` `    ``public` `static` `void` `Main() ` `    ``{ ` `        ``string` `str = ``"3435346456547566345436457867978"``; ` `        ``Console.WriteLine(remainder(str)); ` `    ``} ` `} ` ` `  `// This code is contributed by vt_m. `

## PHP

 ` `

Output:

```4
```

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : vaibhav2992, vt_m, jit_t

Article Tags :
Practice Tags :

3

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.