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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago