Definition:
Arithmetic operations in C are used to perform mathematical calculations on numbers. The common arithmetic operators are + (Addition), - (Subtraction), * (Multiplication), / (Division), and % (Modulus).
Explanation:
This topic explains how arithmetic operators work in C. Using variables and arithmetic operators, we can perform different mathematical calculations and display the results using the printf() function.
Explanation: This program performs addition, subtraction, multiplication, and division on two numbers and displays the results.
#include <stdio.h> #include <conio.h> main() { int a,b,add,sub,div,multi; clrscr(); a=10; b=5; add=a+b; sub=a-b; div=a/b; multi=a*b; printf("\nAddition = %d",add); printf("\nSubtraction = %d",sub); printf("\nDivision = %d",div); printf("\nMultiplication = %d",multi); getch(); }
Output:
Explanation: This program uses the modulus (%) operator to find the remainder when one number is divided by another.
#include <stdio.h> #include <conio.h> main() { int a = 20, b = 3; clrscr(); printf("Remainder = %d", a % b); getch(); }
Output:
Explanation: This program divides two numbers using the division (/) operator and displays the result.
#include <stdio.h> #include <conio.h> main() { int a = 36, b = 6; clrscr(); printf("Division = %d", a / b); getch(); }
Output:
+ operator.printf().#include <stdio.h> main() { int a = 25, b = 15; printf("Addition = %d", a + b); getch(); }
+ operator adds the values of two variables and displays the result using printf().
* operator.#include <stdio.h> main() { int a = 8, b = 9; printf("Multiplication = %d", a * b); getch(); }
* operator multiplies the values of two variables and prints the product.
/ (division) operator.printf() function.#include <stdio.h> main() { int a = 36, b = 6; printf("Division = %d", a / b); getch(); }
/ operator divides one number by another and displays the quotient.