Algorithm Analysis
Let be the input number. Let's identify its hundreds digit and tens digit :
b = n / 100 \% 10;
c = n / 10 \% 10;
The answer will be the number res = 10 * b + c.
The task can also be solved by extracting the digits of the number using formatted input.
Algorithm Implementation
Read the input number . Extract the hundreds digit and the tens digit .
scanf("%d", &n);
b = n / 100 % 10;
c = n / 10 % 10;Calculate and print the result.
res = 10 * b + c;
printf("%d\n", res);Algorithm Implementation – Formatted Input
Extract the digits of thousands, hundreds, tens, and units.
scanf("%1d%1d%1d%1d",&a,&b,&c,&d);Print the hundreds and tens digits.
printf("%d%d\n",b,c);Implementation Using a Character Array
#include <stdio.h>
char *s;
int main(void)
{
s = new char[5];
gets(s);
s[3] = 0;
puts(s+1);
delete[] s;
return 0;
}Java Implementation
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
int n = con.nextInt();
int b = n / 100 % 10;
int c = n / 10 % 10;
int res = 10 * b + c;
System.out.print(res);
con.close();
}
}Java Implementation – String
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
String s = con.nextLine();
System.out.printf("%c%c\n",s.charAt(1),s.charAt(2));
}
}Python Implementation
n = int(input())
b = n // 100 % 10
c = n // 10 % 10
res = 10 * b + c
print(res)