C programming - Arithmetic operators

www.ig‮‬iftidea.com

Arithmetic operators in C programming are used to perform mathematical operations on numeric values. The following arithmetic operators are available in C:

  • Addition (+): Adds two values together.
  • Subtraction (-): Subtracts one value from another.
  • Multiplication (*): Multiplies two values together.
  • Division (/): Divides one value by another.
  • Modulus (%): Computes the remainder of an integer division.

Here is an example of using arithmetic operators in C:

#include <stdio.h>

int main() {
  int num1 = 10;
  int num2 = 3;
  int result;

  result = num1 + num2;
  printf("num1 + num2 = %d\n", result);

  result = num1 - num2;
  printf("num1 - num2 = %d\n", result);

  result = num1 * num2;
  printf("num1 * num2 = %d\n", result);

  result = num1 / num2;
  printf("num1 / num2 = %d\n", result);

  result = num1 % num2;
  printf("num1 %% num2 = %d\n", result);

  return 0;
}

In this example, we declared two integer variables num1 and num2 and initialized them with the values 10 and 3, respectively. We then performed various arithmetic operations on these variables using the arithmetic operators.

The output of the program will be:

num1 + num2 = 13
num1 - num2 = 7
num1 * num2 = 30
num1 / num2 = 3
num1 % num2 = 1

In summary, arithmetic operators in C programming are used to perform mathematical operations on numeric values. The addition, subtraction, multiplication, division, and modulus operators are available in C. These operators can be used with integer, floating-point, and other numeric data types.