{"id":20372,"date":"2021-09-11T15:38:02","date_gmt":"2021-09-11T10:08:02","guid":{"rendered":"https:\/\/python-programs.com\/?p=20372"},"modified":"2021-11-22T18:36:22","modified_gmt":"2021-11-22T13:06:22","slug":"python-program-to-multiply-two-numbers-without-using-multiplication-operator","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-multiply-two-numbers-without-using-multiplication-operator\/","title":{"rendered":"Python Program to Multiply Two Numbers Without Using Multiplication(*) Operator"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Swap Two Numbers using Bitwise Operators<\/a><\/p>\n Given two numbers and the task is to multiply the given two numbers without using multiplication(*) Operator<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to multiply the given two numbers without using multiplication(*) Operator in Python:<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explore more Example Python Programs<\/a> with output and explanation and practice them for your interviews, assignments and stand out from the rest of the crowd.<\/p>\n In the previous article, we have discussed Python Program to Swap Two Numbers using Bitwise Operators Given two numbers and the task is to multiply the given two numbers without using multiplication(*) Operator Examples: Example1: Input: Given First Number = 3 Given Second Number = 6 Output: The multiplication of given two numbers{ 3 * …<\/p>\nGiven First Number = 3\r\nGiven Second Number = 6<\/pre>\n
The multiplication of given two numbers{ 3 * 6 } = 18<\/pre>\n
Given First Number = 15\r\nGiven Second Number = 4<\/pre>\n
The multiplication of given two numbers{ 15 * 4 } = 60<\/pre>\n
Program to Multiply Two Numbers Without Using Multiplication(*) Operator in Python<\/h2>\n
\n
Method #1: Using For Loop (Static Input)<\/h3>\n
\n
# Give the first number as static input and store it in a variable.\r\nfst_numb = 3\r\n# Give the second number as static input and store it in another variable.\r\nscnd_numb = 6\r\n# Take a variable say rslt_sum and initialize its value to 0.\r\nrslt_sum = 0\r\n# Loop from 1 to the given first number using the for loop.\r\nfor itr in range(1, fst_numb+1):\r\n # Inside the loop, add the given second number to the above-initialized variable\r\n # rslt_sum and store it in the same variable rslt_sum.\r\n rslt_sum = rslt_sum+scnd_numb\r\n# Print the variable rslt_sum to get the multiplication of given two numbers without\r\n# using the multiplication(*) Operator.\r\nprint(\"The multiplication of given two numbers{\",\r\n fst_numb, \"*\", scnd_numb, \"} = \", rslt_sum)\r\n<\/pre>\n
The multiplication of given two numbers{ 3 * 6 } = 18<\/pre>\n
Method #2: Using For loop (User Input)<\/h3>\n
\n
# Give the first number as user input using the int(input()) function and\r\n# store it in a variable.\r\nfst_numb = int(input(\"Enter some random number = \"))\r\n# Give the second number as user input using the int(input()) function and\r\n# store it in another variable.\r\nscnd_numb = int(input(\"Enter some random number = \"))\r\n# Take a variable say rslt_sum and initialize its value to 0.\r\nrslt_sum = 0\r\n# Loop from 1 to the given first number using the for loop.\r\nfor itr in range(1, fst_numb+1):\r\n # Inside the loop, add the given second number to the above-initialized variable\r\n # rslt_sum and store it in the same variable rslt_sum.\r\n rslt_sum = rslt_sum+scnd_numb\r\n# Print the variable rslt_sum to get the multiplication of given two numbers without\r\n# using the multiplication(*) Operator.\r\nprint(\"The multiplication of given two numbers{\",\r\n fst_numb, \"*\", scnd_numb, \"} = \", rslt_sum)\r\n<\/pre>\n
Enter some random number = 15\r\nEnter some random number = 4\r\nThe multiplication of given two numbers{ 15 * 4 } = 60<\/pre>\n
\n