tft每日頭條

 > 生活

 > c語言算術運算符和賦值運算符

c語言算術運算符和賦值運算符

生活 更新时间:2024-12-21 13:17:41

算術運算符:

下表是顯示了C語言支持的所有算術運算符。假設變量A的值是10,變量B的值是20。

c語言算術運算符和賦值運算符(C語言運算符之算術運算符)1

創建源代碼文件: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 %d\n", c );

c = a - b;

printf("Line 2 - Value of c is %d\n", c );

c = a * b;

printf("Line 3 - Value of c is %d\n", c );

c = a / b;

printf("Line 4 - Value of c is %d\n", c );

c = a % b;

printf("Line 5 - Value of c is %d\n", c );

c = a ;

printf("Line 6 - Value of c is %d\n", c );

c = a--;

printf("Line 7 - Value of c is %d\n", 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

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关生活资讯推荐

热门生活资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved