Hello , Actaully i am confused that how we can multiply two number without using any operators.? please help me giving yours ideas....
Hello dear thanks for Your reply but You have use * operator to call a functions.. my question is that witout using any operators how we can multiply two numbers....
Use function multiply($x,$y){ $z = array(); for($i=0; $i<$y; $i++){ $z[$i] = $x; } return array_sum($z); } echo(multiply(5,4)); and if you cannot use "for" statement write $x[0] = 5; $x[1] = 5; $x[2] = 5; $x[3] = 5; echo array_sum($x);
Are you referring to signed multiplication x86 ASM instruction which can be called from C++/Java as below? asm(imul dest, src1, imm_src); this does dest := src1 * imm_src
Without using any operator??? I think there is a way in List where you need to Give multiply ( 2 3 ) But not sure about that
The question is a bit confusing - or at least difficult. Do you mean is there a quick way of multiplying a number by 2? In C or C++, you can do this by shifting, e.g. x = x << 1;
#include<stdio.h> main() { int a,b,result; printf("nEnter the numbers to be multiplied :"); scanf("%d%d",&a,&b); result=0; while(b != 0) // Iterate the loop till b==0 { if (b&01) // Logical ANDing of the value of b with 01 result=result+a; // Update the result with the new value of a. a<<=1; // Left shifting the value contained in 'a' by 1. b>>=1; // Right shifting the value contained in 'b' by 1. } printf("nResult:%d",result); }
Note that you can only use shift operations for multiply/divide a number with another number if and only if one of them is a power of 2. That means if p is any number, p << 1 means p X (2^1), i.e.: p X 2 p << 2 means p X (2^2), i.e.: p X 4 p << 3 means p X (2^3), i.e.: p X 8 p << 4 means p X (2^4), i.e.: p X 16 p << 5 means p X (2^5), i.e.: p X 32 ... ... ... p << n means p X (2^n) Similarly, p >> 1 means p / (2^1), i.e.: p / 2 p >> 2 means p / (2^2), i.e.: p / 4 p >> 3 means p / (2^3), i.e.: p / 8 p >> 4 means p / (2^4), i.e.: p / 16 p >> 5 means p / (2^5), i.e.: p / 32 ... ... ... p >> n means p / (2^n) Now you can understand that if you need to multiply/divide p with q using shift operations, either p or q must be a number with power of 2. If you want to check whether a number is a power of 2, use following function. int IsPowerOfTwo(int x) { return (x != 0) && ((x & (x - 1)) == 0); } Code (markup):