|
C Programming Reference >> C Programming Reference Question Bank >> 19/07/07 - 583 Views - Ratings : Question - Write a program to multiply two number without using any' arithemetic operators (*,+,-,/,%) in C.
Answer -
Explanation - Well this is not an easy question, what we do in this code is that we add two numbers using binary logic and multiply them using addition logice in a loop or recursion. This logic is used in digital cirucits which are uses logic gates, so this is an also example of code derived from a digital circuit. First we implement a function addition which takes two number to be added as parameter. This function adds two number bit by bit and also uses recursion call to add a carry value produced in the last step to next order bit. Then to find product of two numbers it implemets a function called multiply which uses a loop to add a number again and again to itself to produce a cumulative result value. For eg to multiply A with B and to store result in C, C is intialised to 0 and a is added to it B times. Answer is not so profound if you understand the explanation above. Reader Comments -
|
|||||