The program must accept an integer N as the input. The task is to form a new number by multiplying each of the digits of N. If any of the digits is 0, omit that digit from multiplication.
Boundary Condition(s):
1 <= N <= 10^9
Input Format:
The first line contains the integer N.
Output Format:
The first line contains the new number formed by multiplying the digits of N.
Example Input/Output 1:
Input:
12345
Output:
120
Explanation:
The multiplication of digits in 12345 is 1 * 2 * 3 * 4 * 5 = 120.
Example Input/Output 2:
Input:
1052
Output:
10
Explanation:
The multiplication of non-zero digits in 1052 is 1 * 5 * 2 = 10.
n = input().strip()
result = 1
for ch in n:
if ch != '0':
result *= int(ch)
print(result)
#include<stdio.h>
int main() {
char n[12];
scanf("%s", n);
int result = 1;
for(int i = 0; n[i] != ' '; i++) {
if(n[i] != '0') {
result *= (n[i] - '0');
}
}
printf("%d", result);
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main() {
string n;
cin >> n;
int result = 1;
for(char ch : n) {
if(ch != '0') {
result *= (ch - '0');
}
}
cout << result;
return 0;
}
import java.util.Scanner;
public class MultiplyDigits {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String n = sc.next();
int result = 1;
for(char ch : n.toCharArray()) {
if(ch != '0') {
result *= (ch - '0');
}
}
System.out.println(result);
}
}