目录

算术运算(Arithmetic Operations)

基本算术运算包括加法,减法,乘法和减法。 它们在数值数据类型上执行,如intfloatdouble

C中的加法运算

下面给出的示例代码解释了C中的添加。

#include <stdio.h>
int main() {
   int op1, op2, sum;      // variable declaration
   op1 = 5;                // variable definition
   op2 = 3;
   sum = op1 + op2;        // addition operation
   printf("sum of %d and %d is %d", op1, op2, sum);
}

该计划的输出应该是 -

sum of 5 and 3 is 8

C中的减法运算

下面给出的示例代码解释了C中的减法运算。

#include <stdio.h>
int main() {
   int op1, op2, sub;      // variable declaration
   op1 = 5;                // variable definition
   op2 = 3;
   sub = op1 - op2;        // subtraction operation
   printf("Output of %d − %d is %d", op1, op2, sub);
}

该计划的输出应该是 -

Output of 5 − 3 is 2 

C中的乘法运算

下面给出的示例代码解释了C中的乘法。星号或*用作乘法运算符。

#include <stdio.h>
int main() {
   int op1, op2, mul;      // variable declaration
   op1 = 5;                // variable definition
   op2 = 3;
   mul = op1 * op2;        // multiplication operation
   printf("Output of %d multiplied by %d is %d", op1, op2, mul);
}

该计划的输出应该是 -

Output of 5 multiplied by 3 is 15

C部门的分部运作

下面给出的示例代码解释了C中的除法。

#include <stdio.h>
int main() {
   int op1, op2, div;      // variable declaration
   op1 = 6;                // variable definition
   op2 = 3;
   div = 6/3;            // division operation
   printf("Output of %d divide by %d is %d", op1, op2, div);
}

该计划的输出应该是 -

Output of 6 divide by 3 is 2
↑回到顶部↑
WIKI教程 @2018