Example 1: if statement // Program to display a number if it is negative#include<stdio.h>intmain(){intnumber;printf("Enter an integer: ");scanf("%d", &number);// true if number is less than 0if(number <0) {printf("You entered %d.\n", number); }printf("The if statement is ...
&day);// 接受用户从键盘输入的数据if(day ==0)printf("星期天\n");elseif(day ==1)printf("星期一\n");elseif(day ==2)printf("星期二\n");elseif(day ==3)printf("星期三\n");elseif(day ==4)printf("星期四\n");else
*/#include<stdio.h>intmain(){intday=0;// 定义一个整数变量用于接受键盘输入的数字printf("请输入0-6之间的数字:");// 提示用户输入scanf("%d",&day);// 接受用户从键盘输入的数据if(day==0)printf("星期天\n");elseif(day==1)printf("星期一\n");elseif(day==2)printf("星期二\n");else...
printf( "You are really old\n" ); /* Executed if no other statement is */ } return 0; }More interesting conditions using boolean operators Boolean operators allow you to create more complex conditional statements. For example, if you wish to check if a variable is both greater than five...
C - Assignment Operators C - Unary Operators C - Increment and Decrement Operators C - Ternary Operator C - sizeof Operator C - Operator Precedence C - Misc Operators Decision Making in C C - Decision Making C - if statement C - if...else statement ...
1 2 int find_smallest(int a, int b) { } Check Code Video: Arithmetic Operators in C Previous Tutorial: C Input Output (I/O) Next Tutorial: C if...else Statement Share on: Did you find this article helpful?Our premium learning platform, created with over a decade of experience...
3. There can be any number of else..if statement in a if else..if block. 4. If none of the conditions are met then the statements in else block gets executed. 5. Just like relational operators, we can also use logical operators such as AND (&&), OR(||) and NOT(!)....
If parenthesis are nested, the evaluation begins with the innermost sub expression. The precedence rule is applied in determining the order of application of operators in evaluating sub expressions. The associability rule is applied when two or more operators of the same precedence level appear in ...
Use the if statement to specify a block of code to be executed if a condition is true.Syntax if (condition) { // block of code to be executed if the condition is true}Note that if is in lowercase letters. Uppercase letters (If or IF) will generate an error....
if (3 = X)会导致编译错误,从而节省大量时间。 没有;那行不通。 -4 <= X是0或1,始终小于8。 Is the syntax in if statement valid? 语法是有效的,但是不会满足您的期望。<=是C中的一个普通的左关联二进制中缀运算符,因此 1 -4<=X<=8 ...