<返回更多

C语言运算符之算术运算符

2019-11-13    
加入收藏

算术运算符:

下表是显示了C语言支持的所有算术运算符。假设变量A的值是10,变量B的值是20。

C语言运算符之算术运算符

创建源代码文件:marithmetic_operators.c,代码如下:

#include <stdio.h>

void main() {

int a = 21;

int b = 10;

int c ;

c = a + b;

printf("Line 1 - Value of c is %dn", c );

c = a - b;

printf("Line 2 - Value of c is %dn", c );

c = a * b;

printf("Line 3 - Value of c is %dn", c );

c = a / b;

printf("Line 4 - Value of c is %dn", c );

c = a % b;

printf("Line 5 - Value of c is %dn", c );

c = a++;

printf("Line 6 - Value of c is %dn", c );

c = a--;

printf("Line 7 - Value of c is %dn", c );

}

执行上面的代码,得到如下结果:

Line 1 - Value of c is 31

Line 2 - Value of c is 11

Line 3 - Value of c is 210

Line 4 - Value of c is 2

Line 5 - Value of c is 1

Line 6 - Value of c is 21

Line 7 - Value of c is 22

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>