multiply

Python program to multiply two numbers without using arithmetic operator

Python program to multiply two numbers without using arithmetic operator

problem – Python program to multiply two numbers without using arithmetic operator

 

In this tutorial, we will discuss the concept of  multiplying two numbers without using arithmetic operator in Python language. 

In this post, we will learn how to get the product of two number without arithmetic operator in Python programming language

 

multiply two numbers without using arithmetic operator

Python program to find product of two numbers

Using for loop – Program 1

This program is used to find the multiplication of two numbers entered by the user – using for loop without arithmetic operator

#How to print product of two numbers without using "*" operator in Python
num1=int(input("Enter a number for num1: "))#get input from user for num1
num2=int(input("Enter a number for num2: "))#get input from user for num2
product=0
for i in range (1,num2+1):  #Python for loop
 product=product+num1       #product+=num1
print("Multiplication of numbers: ",product) #Display multiplication of numbers

When the above code is executed, it produces the following result

Enter a number for num1: 25
Enter a number for num2: 50
Multiplication of numbers: 1250

 

Using function – Program 2

This program is used to find the multiplication of two numbers entered by the user – using if elif statements without arithmetic operator

x=int(input("Enter a number for x: "))#get input from user for x
y=int(input("Enter a number for y: "))#get input from user for y


def findProduct(x,y):  #Python function
    if y<0:
        return -findProduct(x,-y)
    elif y == 0:
        return 0
    elif y == 1:
        return x
    else:
         return x+ findProduct(x,y-1)
print("product of two numbers: ",findProduct(x,y))
#Display result on the screen

When the above code is executed, it produces the following result

Enter a number for x: 30
Enter a number for y: 12
product of two numbers: 360

 

 

Similar post

C program to multiply two numbers without using arithmetic operator

C++ program to multiply two numbers without using arithmetic operator

Java program to multiply two numbers without using arithmetic operator

Multiply two numbers in Python

 

Suggested for you

Operators in Python

For loop in Python

Data type in Python

If elif statements in Python

Python function

 

Java program to multiply of two numbers without using arithmetic operator
Program to calculate factorial of a number using recursion in Java
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago