两数相加,而无需使用运营商 [英] Adding two numbers without using operators

查看:76
本文介绍了两数相加,而无需使用运营商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这下code的另外两个数字而无需使用 + 运营商。

code以添加3和4:

 的printf(%D的printf(%* C%* C,3',4''));

现在的printf()返回结果的字符数
%* C 忽略下一个字符,它遇到。但尽管如此,我不能够理解这code。任何帮助将是AP preciated。


解决方案

的printf(%* C,N,C)打印字符 C N 倍。所以code打印后跟4个空格3位,和 printf的返回打印的字符的数目,这显然是3 + 4,在完成的问题。

I found this following code for addition of two numbers without using the + operator.

code to add 3 and 4:

printf("%d",printf("%*c%*c",3,' ',4,' '));

Now printf() returns the number of characters in the result and %*c ignores the next character that it encounters. But still, I am not able to understand this code. Any help would be appreciated.

解决方案

printf("%*c", n, c) prints the character c, n times. So the code prints 3 spaces followed by 4 spaces, and printf returns the number of characters printed, which is obviously 3 + 4, completing the problem.

这篇关于两数相加,而无需使用运营商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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