我很抱歉,如果以前曾经问过这个,但我是C的初学者,我想知道是否有人可以帮助解释()下面代码中括号的使用,我从在线教程中获取它并运行正常,但其中有一部分我不明白.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int age;
printf("Please enter the age");
scanf("%d", &age);
if (age > 18 /*condition */ ) {
printf("You may enter the club");
if (age < 21)
{
printf("The age is greater than 18 but less than 21");
Run Code Online (Sandbox Code Playgroud)
} 其他
(printf("The age is greater than 18 and greater than 21"));
} else if (age == 18)
{
printf("The age is equal to 18");
}
else {
printf("The age is not greater than …Run Code Online (Sandbox Code Playgroud) 我在C上尝试一个简单的十进制到二进制转换器,但输入十进制数后控制台没有响应.这是我的代码.
int convertDecimalToBinary(int n);
int main()
{
int n;
printf("Enter a decimal number: ");
scanf("%d", &n);
convertDecimalToBinary(n);
printf("%d in decimal = %d in binary", n, convertDecimalToBinary(n));
return 0;
}
int convertDecimalToBinary(int n)
{
int binaryNumber = 0;
int remainder, i = 1;
while (n!=0);
{
remainder = n%2;
n /= 2;
binaryNumber += remainder*i;
i *= 10;
}
printf("%d\n",binaryNumber);
return binaryNumber;
}
Run Code Online (Sandbox Code Playgroud)
我没有收到任何错误消息,我被提示输入一个十进制数字,但之后它没有响应.
c ×2