如何在不使用+或*运算符的情况下以编程方式执行乘法运算。 [英] How can we perfom multiplication programatically without using + or * operator.

查看:68
本文介绍了如何在不使用+或*运算符的情况下以编程方式执行乘法运算。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们如何在不使用+或*

运算符的情况下以编程方式执行乘法运算。

任何人都可以帮助这个。


Jagadeesh。


How can we perfom multiplication programatically without using + or *
operator.
Can any one help out in this one.

Jagadeesh.

推荐答案

mj ******** @ yahoo.co.in 写道:
我们如何在不使用+的情况下以编程方式进行乘法运算或*
操作员。
任何人都可以帮忙。
How can we perfom multiplication programatically without using + or *
operator.
Can any one help out in this one.




如果你以二进制格式概念化数值,那么左

将值移动N类似于将值乘以2 ^ N.



If you conceptualise the numerical values in a binary format, then left
shifting the value by N is similar to multiplying the value by 2^N.


mj ******** @ yahoo.co.in 说:
如何在不使用+或*
运算符的情况下以编程方式进行乘法运算。
How can we perfom multiplication programatically without using + or *
operator.




可以使用^(xor),& (和),<< (左移)

正确方式。


乘法重复加法(即循环加法)。


或者,你可以加倍减半,如果你小心的话是

奇数。请注意,加倍将需要使用上面描述的添加

(因为你不允许使用*运算符)。


这已经足够了 - 现在做你自己的作业。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)



Addition can be done by using ^ (xor), & (and), and << (left shift) in the
proper way.

Multiplication is repeated addition (i.e. addition in a loop).

Alternatively, you can double and halve, if you''re careful in the case of an
odd number. Note that doubling will require using addition as described
above (since you are not allowed the * operator).

That''s enough of a hint - now do your own homework.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


mj ******** @ yahoo.co.in 写道:

怎么能我们以编程方式执行乘法而不使用+或*
运算符。
任何人都可以帮助这个。

How can we perfom multiplication programatically without using + or *
operator.
Can any one help out in this one.




#include< stdio。 h>


int mult(int a,int b)

{

int c = 0;

而(a--)c - = b;

返回-c;

}


int main( void)

{

int a = 5;

int b = 6;


printf (%dx%d =%d \ n,a,b,mult(a,b));


返回0;

}


-

:wq

^ X ^ Cy ^ K ^ X ^ C ^ C ^ C ^ C



#include <stdio.h>

int mult(int a, int b)
{
int c = 0;
while(a--) c -= b;
return -c;
}

int main(void)
{
int a = 5;
int b = 6;

printf("%d x %d = %d\n", a, b, mult(a, b));

return 0;
}

--
:wq
^X^Cy^K^X^C^C^C^C


这篇关于如何在不使用+或*运算符的情况下以编程方式执行乘法运算。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆