Algorithm Analysis
Let be the input number. Let be the number of hundreds, be the number of tens, be the number of ones. Then the answer will be the value of a \times b \times c - (a + b + c).
Algorithm Implementation
Read the value of , calculate its absolute value.
scanf("%d",&n);
if (n < 0) n = -n;Extract from the number the number of hundreds , tens , and ones .
a = n / 100;
b = (n / 10) % 10;
c = n % 10;Calculate and output the answer.
res = a * b * c - (a + b + c);
printf("%d\n",res); Implementation with Formatted Input
The first character can be a minus, read it. If there is no minus, then nothing will be read into ch.
#include <stdio.h>
int a, b, c, res;
char ch;
int main(void)
{
scanf("%[^0-9]",&ch);
scanf("%1d%1d%1d",&a,&b,&c);
res = a * b * c - (a + b + c);
printf("%d\n",res);
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();
if (n < 0) n = -n;
int a = n / 100;
int b = (n / 10) % 10;
int c = n % 10;
int res = a * b * c - (a + b + c);
System.out.println(res);
con.close();
}
}Python Implementation
n = int(input())
if n < 0: n = -n
a = n // 100
b = (n // 10) % 10
c = n % 10
res = a * b * c - (a + b + c)
print(res)