TCS Coding Questions 2022 Day 2 Slot 1
Coding Question 2 for 2022 (September slot)
In this article, we will discuss about the TCS Coding Question which is asked in the TCS placement test. This type of Coding Questions will help you to crack your upcoming TCS exam as well as during your interview process.
TCS Coding Question Day 2 Slot 1 – Question 2
A supermarket maintains a pricing format for all its products. A value N is printed on each product. When the scanner reads the value N on the item, the product of all the digits in the value N is the price of the item. The task here is to design the software such that given the code of any item N the product (multiplication) of all the digits of value should be computed(price).
Example 1:
Input :
5244 -> Value of N
Output :
160 -> Price
Explanation:
From the input above
Product of the digits 5,2,4,4
5*2*4*4= 160
Hence, output is 160.
C
C++
Java
Python
C
Run
#include<stdio.h>
#include<limits.h>
int main() {
char s[100];
scanf("%s", s);
int p = 1;
for (int i = 0; i < strlen(s); i++) {
p *= (s[i] - '0');
}
printf("%d", p);
return 0;
}
}
C++
Run
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
int p=1;
for(auto i:s)
p*=(i-'0');
cout<< p;
}
Java
Run
import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int res=1;
while(n > 0)
{
res=res*(n%10);
n=n/10;
}
System.out.println(res);
}
}
}
Python
Run
n=input()
p=1
for i in n:
p*=int(i)
print(p)
