"&放大器;&安培;"和"和"操作者用C [英] "&&" and "and" operator in C
问题描述
我试图来计算两个整数的最大公约数。
I am trying to calculate the Greatest Common Denominator of two integers.
C code:
#include <stdio.h>
int gcd(int x, int y);
int main()
{
int m,n,temp;
printf("Enter two integers: \n");
scanf("%d%d",&m,&n);
printf("GCD of %d & %d is = %d",m,n,gcd(m,n));
return 0;
}
int gcd(int x, int y)
{
int i,j,temp1,temp2;
for(i =1; i <= (x<y ? x:y); i++)
{
temp1 = x%i;
temp2 = y%i;
if(temp1 ==0 and temp2 == 0)
j = i;
}
return j;
}
在if语句,注意逻辑运算。这是和
不是&放大器;&安培;
(错误)。在code工作没有任何警告或错误。
In the if statement, note the logical operator. It is and
not &&
(by mistake). The code works without any warning or error.
有一个和
经营者使用C?我使用的 orwellDev-C ++ 5.4.2(在 C99 模式)。
Is there an and
operator in C? I am using orwellDev-C++ 5.4.2 (in c99 mode).
推荐答案
点击这里,查看页面 iso646.h
这头定义了11个宏的是一些常见的运营商的对应文字。和
是定义之一。
This header defines 11 macro's that are the text equivalents of some common operators.
and
is one of the defines.
请注意,我只能测试这一个C ++编译器,所以我不能肯定,如果你可以使用这个具有严格的C编译器。
Note that I can only test this for a C++ compiler so I'm not certain if you can use this with a strict C compiler.
修改我刚刚在这里 C编译器测试,它确实工作。
EDIT I've just tested it with a C compiler here and it does work.
这篇关于&QUOT;&放大器;&安培;&QUOT;和&QUOT;和&QUOT;操作者用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!