Remainder mod 11
Given a string (of maximum length 1000) representing a large number. Output is modulo of 11.
Input specification:
Input 1: A large number in the form of a string.
Output Specification:
Return the remainder modulo 11 of input 1.
Example 1:
Input 1: 121
Output: 0
Explanation:
121 mod 11 = 0
Example 2:
Input 1: 13
Output: 2
Explanation:
13 mod 11 = 2
Solution in Python 3:
#https://codewindow.in
#join our telegram channel
x=int(input())
print(x%11)
# Telegram @codewindow
Solution in JAVA :
import java.util.*;
class CodeWindow {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
int len = str.length();
int num, rem = 0;
for (int i = 0; i < len; i++) {
num = rem * 10 + (str.charAt(i) - '0');
rem = num % 11;
}
System.out.println(rem);
}
}
Solution in C :
#include <stdio.h>
#include <string.h>
int main()
{
char str[1000];
scanf("%s",str);
int len = strlen(str);
int num, rem = 0;
for (int i = 0; i < len; i++) {
num = rem * 10 + (str[i] - '0');
rem = num % 11;
}
printf("%d",rem);
}
Solution in C++ :
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str;
cin >> 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;
}
cout << rem;
}
Output:
13
2