Knowee
Questions
Features
Study Tools

Multiply the given two numbers without using * operator.Input Format:Accept two integers as input.Output Format:Print the output as product of input1 and input2Constraints:1 <= INPUT <= 10^15Sample Input :10 2Sample Output :20

Question

Multiply the given two numbers without using * operator.Input Format:Accept two integers as input.Output Format:Print the output as product of input1 and input2Constraints:1 <= INPUT <= 10^15Sample Input :10 2Sample Output :20

🧐 Not the exact question you are looking for?Go ask a question

Solution

To multiply two numbers without using the * operator, you can use repeated addition. Here are the steps to do it:

  1. Accept two integers as input.
  2. Initialize a variable to store the product, let's call it "result", and set it to 0.
  3. Use a loop to iterate from 1 to the value of the second input number.
  4. Inside the loop, add the value of the first input number to the result variable.
  5. After the loop finishes, the value of the result variable will be the product of the two input numbers.
  6. Print the value of the result variable as the output.

Here is the code in Python:

# Accept two integers as input
input1, input2 = map(int, input().split())

# Initialize the result variable
result = 0

# Multiply using repeated addition
for i in range(1, input2 + 1):
    result += input1

# Print the output
print(result)

For the given sample input of 10 and 2, the output will be 20.

This problem has been solved

Similar Questions

Multiply two decimal numbers and print the product with a precision of 2 decimal places .Input Format:Accept two decimal values as inputOutput Format:Print the product with 2 precisionConstraints:        1<=N1,N2<= 10^15Sample Input 1:125.58 78.65Sample Output 1:9876.87Sample Input 2:2.24 3.56Sample Output 2:7.97

Given 2 numbers, find the minimum of these 2 numbersInput Format:Accept two integer values as inputs.Output Format:Print the output as "Minimum of INPUT1 and INPUT2 is  ____".Constraints:-10^15 <= INPUT <= 10^15Sample Input 1:10 20Sample Output 1:Minimum of 10 and 20 is 10Sample Input 2:10 200Sample Output 2:Minimum of 10 and 200 is 10

Get two integers from user and print the absolute difference between two integersInput Format:Accept two integers as inputOutput Format:Print the absolute differenceConstraints:1<=N1,N2<=10^9Sample Input 1:10 20Sample Output 1:10Sample Input 2:78 25Sample Output 2:53

Problem Statement:Given 2 numbers, print the first number as a 5-digit number and print the second number in the next line with 5 width spaceExplanation: If numbers are 25 and 98,print the first number as 00025 and second number as 3 space and 98(   98).Input Format:Accept the two integer as a inputOutput Format:5 digit number format followed by number with 5 width space in new line.Constraints:10^-15 <= num1,num2 <= 10^15Sample Input 1:34 7896Sample Output 1:000347896Sample Input 2:-125 -36Sample Output 2:-0125-36

Problem Statement:Find the product of numbers from 1 to given nInput FormatA single integer - nOutput FormatPrint the productConstraints1<= n <= 1000000NOTE : The calculated product value might exceed integer range.Sample Input 1:10Sample Output 1:3628800Sample Input 2:5Sample Output 2:120

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.