我想知道答案,它是怎么来的? [英] I want to know the answer and how did it came?
本文介绍了我想知道答案,它是怎么来的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include<stdio.h>
#include<conio.h>
void main()
{
printf("%d",8-6/8*6);
getch();
}
我的尝试:
i尝试了这段代码,答案即将到来8怎么可能是8 cauz 8-6 = 2和2/8 * 6即2/48 = 24
What I have tried:
i tried this code and answer is coming 8 how can it be 8 cauz 8-6=2 and 2/8*6 i.e 2/48 = 24
推荐答案
Quote:
2/8 * 6即2/48 = 24
2/8*6 i.e 2/48 = 24
看起来你需要检查你的小学数学知识。
数学:
8-6 / 8 * 6表示8 - ((6/8)* 6)
8 - ((6/8)* 6)=> 8-(36/8)
8-(36/8)=> 8-4.5 => 3.5
使用C,还有一个技巧:
a除以整数除法的整数,它给出一个整数作为答案,所以6/8 => 0
Looks like you need to check your primary school knowledge in mathematics.
Mathematics:
8-6/8*6 means 8-((6/8)*6)
8-((6/8)*6) => 8-(36/8)
8-(36/8) => 8-4.5 => 3.5
And with C, there is 1 more trick:
a division with integers in an integer division and it gives an integer as answer, so 6/8 => 0
答案是8.
8-6 / 8 * 6
看看运算符的优先级及其相关性。
/,*优先级高于 - 且关联性从左到右。
首先,6 / 8计算结果为0然后0 * 6 = 0
和8-0为8。
Answer is 8.
8-6/8*6
Look at the Precedence of Operator and their Associativity.
/ , * have higher Precedence than - and Associativity is left to right.
So first, 6/8 evaluates to 0 then 0*6 = 0
and 8-0 is 8.
参见 C ++内置运算符,优先级和关联性 [ ^ ]。
这篇关于我想知道答案,它是怎么来的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文