Tag: 如果声明

C简易程序不工作 – “如果”

我试着编写一个简单的程序,比较3个数字并打印出最大的数字,但它会继续打印所有3个数字而且我不明白为什么。 那是我的代码: #include int main() { int x = 10; int y = 8; int z = 3; if((x > y) && (x > z)); { printf(“%d”,x); } if((y > x) && (y > z)); { printf(“%d”,y); } if((z > x) && (z > y)); { printf(“%d”,z); } return 0; } 谢谢您的帮助!

如果声明不工作立即结束程序

我正在制作一个天气男人代码但是当我要求温度时它会结束程序。 这是代码。 #include int main(void) { int a; int b; int c; int d; printf(“What Is Your Name?\n”); scanf(“%s”,&b); printf(“Hi %s\n”, &b); sleep(1); printf(“Im Your Own Weather Man\n”); sleep(1); printf(“Isn’t That Great!\n”); sleep(1); printf(“Please Type A Number In\n”); sleep(1); scanf(“%d”,&a); //checking out the number you wrote if(a3) { printf(“:(\n”); } if(a==3) { printf(“Its Snowing!\n”); printf(“%c\n”,3); […]

这个简单的If-Statement有什么作用?

我不是程序员(开始学习Python)。 请帮我理解这个伪代码: { if ( !*(sub_676578() + 2644) ) { EnterCriticalSection(&CriticalSection); ++dw_FrameCounter; if ( !b_AnimFlag ) { if ( !b_PauseFlag ) { dw_TFraction += 1092; if ( dw_TFraction >> 16 ) { ++dw_TSeconds; dw_TFraction = dw_TFraction; } dw_CDFraction += 1092; if ( dw_CDFraction >> 16 ) { if ( b_TimerDirection & 2 ) { ++dw_CDSeconds; […]

嵌套if和&&之间有什么区别?

写作之间有什么区别: if(condition1 && condition2){ //some code } 和: if(condition1){ if(condition2){ //some code } } 如果有,哪一个更好?

C if语句带&& – 首先执行哪个函数?

如果我在C中有一个if语句,它看起来像: if( function1() > 0 && function2() > 0 ){ //blah } 哪个函数将首先执行并始终按该顺序执行?

排序3个人的年龄

/* to find the age of individuals according to youngest to oldest */ #include int main(void) { int age1, age2, age3, youngest, middle, oldest; { printf (“Enter the age of the first individual: “); scanf (“%d”, &age1); printf (“Enter the age of the second individual: “); scanf (“%d”, &age2); printf (“Enter the age of the […]

预处理器#if指令

我正在写一个很大的代码,我不希望它都在我的main.c中,所以我写了一个带有函数的IF-ELSE语句的.inc文件,我想知道它是这样编写的: #if var==1 process(int a) { printf(“Result is: %d”,2*a); } #else process(int a) { printf(“Result is: %d”,10*a); } #endif 我试图编译它,但它给了我错误,或者在最好的情况下,它只是在第一个函数进程上没有检查var变量(它被设置为0)。

没有先前’if’的’else’

我刚刚开始学习C编程,所以我并没有真正处于高级水平。 忍受我! 我有这段代码,我想我很容易理解我要做的事情。 但是我收到一个错误,说没有if之前调用了最后一个else。 我怀疑问题是if和else之间的if-else语句。 你们怎么解决它? int talet; scanf(“%d”, &talet); int i = 1; while (i <= 99) { int a; { if (i % talet == 0 || talet == (i / 10) % 10 || talet == i % 10) { if (talet % 10 == 0) printf("\n"); else continue; } printf("burr "); […]

如果(TRUE)在C中是个好主意吗?

在C编程语言中,我的理解是变量只能在代码块的开头定义,而变量将具有声明它的块的范围。考虑到这一点,我想知道它是否是被认为是人为地创建新范围的不良做法,如下例所示: void foo() { … Do some stuff … if(TRUE) { char a; int b; … Do some more stuff … } … Do even more stuff … } 假设在宏定义中将TRUE设置为1,这段代码是否会被认为是“好代码”,还是让经验丰富的程序员在想到它时会畏缩不前? 感谢您的输入! 编辑:在回答一些答案时,我正在使用的代码需要与一些非常古老的遗留系统一起工作。 虽然按照C99的假设操作会很好,但我们真的不能保证他们会拥有它。

将货币值作为浮点数进行比较不起作用

如果我输入0.01或0.02,程序会立即退出。 我该怎么办? 谢谢。 我的post主要是代码。 我需要添加更多细节。 #include char line[100]; float amount; int main() { printf(“Enter the amount of money: “); fgets(line, sizeof(line), stdin); sscanf(line, “%f”, &amount); if (amount == 0.0) printf(“Quarters: 0\nDimes: 0\nNickels: 0\nPennies: 0”); if (amount == 0.01) printf(“Quarters: 0\nDimes: 0\nNickels: 0\nPennies: 1”); if (amount == 0.02) printf(“Quarters: 0\nDimes: 0\nNickels: 0\nPennies: 2”); return (0); }