300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > c语言if else语句_查找C程序的输出(如果为else语句)| 设置1

c语言if else语句_查找C程序的输出(如果为else语句)| 设置1

时间:2024-01-27 13:10:03

相关推荐

c语言if else语句_查找C程序的输出(如果为else语句)| 设置1

c语言if else语句

Find the output of the following programs,

查找以下程序的输出,

Program 1)

程序1)

#include <stdio.h>int main(){int x = 400, y, z;if (x >= 500)y = 400;z = 300;printf("%d %d\n", y, z);return 0;}

Output

输出量

32766 300

Explanation:

说明:

In the code, the condition x>=500 is false, so the variable y will not be assigned and the statement z=300 is written after the conditional statement, so it will be assigned with 300. Thus, the value of y will be a garbage value and value of z will be 300.

在代码中,条件x> = 500为假,因此将不分配变量y,并且在条件语句之后写入语句z = 300 ,因此将其分配为300。因此, y的值将为垃圾值和z的值为300。

Program 2)

程序2)

#include <stdio.h>int main(){int p = 800, q, r;if (p >= 700)q = 600;r = 500;printf("%d %d\n", q, r);return 0;}

Output

输出量

600 500

Explanation:

说明:

In the code, the condition p>=700 is true, so the variable q will be assigned with the value 600 and the statement r=500 is written after the conditional statement, so it will be assigned with 500. Thus, the value of q will be a 600 value and value of r will be 500.

在代码中,条件p> = 700为true,因此将为变量q分配值600,并在条件语句后写入语句r = 500 ,因此将其分配为500。因此, q将是600的值,而r的值将是500。

Program 3)

程序3)

#include <stdio.h>int main(){int a = 30, b = 40;if (a == b);printf("%d %d\n", a, b);return 0;}

Output

输出量

30 40

Explanation:

说明:

In the code, the condition if(a==b); is terminated with semicolon so the statement printf("%d %d\n",a,b); will not be consider as a body of the if statement. Thus, the program will print the value of a and b.

在代码中,条件为if(a == b); 以分号终止,因此语句printf(“%d%d \ n”,a,b); 不会被视为if语句的主体。 因此,程序将打印a和b的值。

Program 4)

程序4)

#include <stdio.h>int main(){int e = 4;float f = 4.0;if (e == f) {printf("E and F are equal\n");}else {printf("E and F are not equal");}return 0;}

Output

输出量

E and F are equal

Explanation:

说明:

In the code, variable e is an integer type and variable f is a float type, while comparing them with an if statement (if(e==f)), the value of f will be truncated to an integer (due to implicit type conversion). Thus, the condition will be true and"E and F are equal"will be printed.

在代码中,变量e是整数类型,变量f是浮点类型,将它们与if语句( if(e == f) )进行比较时, f的值将被截断为整数(由于隐式类型)转换)。 因此,条件为真,并且将打印“ E和F相等”。

Program 5)

程序5)

#include <stdio.h>int main(){int p = 4, q, r;q = p = 15;r = p < 15;printf("p = %d q = %d r = %d\n", p, q, r);return 0;}

Output

输出量

p = 15 q = 15 r = 0

Explanation:

说明:

In the code, the statement q = p = 15; is assigning 15 to the variables p and q and the statement r = p<15; is assigning 0 to the variable r because p is not less than 15 (condition is false). Thus, the value of p, q and r will be 15, 15, and 0.

在代码中,语句q = p = 15; 将变量p和q赋值为15,并且语句r = p <15; 因为p不小于15(条件为假),所以将0赋给变量r 。 因此, p , q和r的值将分别为15、15和0。

Program 6)

计划6)

#include <stdio.h>int main(){int i = 65;char j = 'A';if (i == j) {printf("This place is beautiful\n");}else {printf("This place is not beautiful\n");}return 0;}

Output

输出量

This place is beautiful

Explanation:

说明:

The character variable stores the ASCII code of the given character (it's also a number type of variable). Thus, the value of j will be 65 (The ASCII Code of 'A' is 65). So the condition if(i==j) will be true and"This place is beautiful"will be printed.

字符变量存储给定字符的ASCII码(它也是变量的数字类型)。 因此, j的值为65(“ A”的ASCII码为65)。 因此条件if(i == j)将为true,并且将打印“这个地方很漂亮”。

Program 7)

计划7)

#include <stdio.h>int main(){float p = 13.25, q = 14.5;if (p = q) {printf("Hello\n");}return 0;}

Output

输出量

Hello

Explanation:

说明:

In the statement if(p=q), p=q is not a comparison operation, we used = (assignment operator), thus the value of q will be assigned into p and the statement will be evaluated to14.5which is a non-zero value and conditional will be true.

在语句if(p = q) , p = q不是比较运算的情况下,我们使用= (赋值运算符),因此q的值将分配给p,并且该语句的计算结果为14.5,这不是零值和条件将为真。

Recommended posts

推荐的帖子

Find output of C programs (if else statement) | set 2

查找C程序的输出(如果为else语句)| 设置2

Find output of C programs (Bitwise Operators) | Set 1

查找C程序的输出(按位运算符)| 套装1

Find output of C programs (Bitwise Operators) | Set 2

查找C程序的输出(按位运算符)| 套装2

Find output of C programs (Strings) | Set 1

查找C程序的输出(字符串)| 套装1

Find output of C programs (Strings) | Set 2

查找C程序的输出(字符串)| 套装2

Find output of C programs (Structures) | Set 1

查找C程序的输出(结构)| 套装1

Find output of C programs (Mixed topics) | Set 1

查找C程序的输出(混合主题)| 套装1

Find output of C programs (Mixed topics) | Set 2

查找C程序的输出(混合主题)| 套装2

Find output of C programs (Mixed topics) | Set 3

查找C程序的输出(混合主题)| 套装3

Find output of C programs (Character) | Set 1

查找C程序的输出(字符)| 套装1

Find output of C programs (floating point) | Set 1

查找C程序的输出(浮点数)| 套装1

Find output of C programs (For loops) | Set 1

查找C程序的输出(用于循环)| 套装1

Find output of C programs (Arrays) | Set 1

查找C程序的输出(数组) 套装1

翻译自: /c/if-else-find-output-of-programs-c-set-1.aspx

c语言if else语句

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。