Arithmetic Operators


Arithmetic Operators

Operators are special symbols in the C programming language used to execute a variety of mathematical and logical operations on the operands and return the desired results. Arithmetic Operators, Relational Operators, Shift Operators, Logical Operators, Bitwise Operators, Ternary or Conditional Operators, and Assignment Operators are all available in the C programming language. However, this article will look at the Arithmetic Operator in the C programming language.

On the provided operands, the Arithmetic Operator is used to execute mathematical operations such as addition, subtraction, multiplication, division, modulus, etc. Examples of arithmetic operators are 5 + 3 = 8, 5 - 3 = 2, 2 * 4 = 8, and so on. Let's look at the many forms of Arithmetic Operators in C programming.

Plus Operator

It's a basic Plus (+) Operator used to combine two operands. To add the provided operand, we may use the Plus Operator with many data types such as integer, float, long, double, enumerated, and string data.

Syntax C = A + B; for example, there are two operands, 5 and 6, and we wish to sum them. As a result, between the supplied numbers that yield integer data, we apply the '+' Operator 11.

Program1.c

1. #include <stdio.h> 2. #include <conio.h> 3. int main () 4. { 5. // declare integer variables 6. int num1, num2, res; 7. // declare float data type number 8. float f1, f2, res1; 9. // declare double variables 10. double d1, d2, res2; 11. printf (" Enter two integer numbers: "); 12. scanf ("%d %d", &num1, &num2); 13. res = num1 + num2; // use + operator 14. 15. scanf (" percent f percent f," &f1, &f2); res1 = f1 + f2; / utilise the + operation 16. 17. printf (" Enter two double-valued numbers: n "); scanf (" percent lf percent lf", &d1, &d2); res2 = d1 + d2; / utilise the + operation 18. return 0; printf (" The sum of two integer numbers: percent dn", res); printf (" The sum of two float numbers: percent fn ", res1); printf (" The sum of two double numbers: percent lf ", res2) 19. }

Output

Enter two integer numbers: 25 35 Enter two float numbers: 79.21 67.79 Enter two double data type numbers: 234.123 345.341 60 is the product of two integer integers. 147.000000 is the sum of two float numbers. The sum of two double numbers: 579.464000

Minus Operator

The negative (-) sign represents the minus operator, and it's used to get the result of subtracting the first integer from the second. In the computer language, the data type of the provided number might be several kinds such as int, float, double, long double, and so on. For example, there are two operands, 15 and 6, and we want the result of their subtraction. So, we apply the'- ' Operator between the provided integers that produce data 9.