AnkitWebLogic

Example 1: Write a program to use Arithmetic Operator(+, -, /, *, %) 1

#include<stdio.h>
void main()
{
    int a=2, b=3;
    int sum, sub, mul, idiv, mod;
    float fdiv;
   
    sum = a + b;
    sub = a - b;
    mul = a * b;
    idiv = a / b;
    fdiv = (float)a / b;
    mod = b%a;
	
    printf("\nSum = %d",sum);
    printf("\nSub = %d",sub);
    printf("\nMul = %d",mul);
    printf("\niDiv = %d",idiv);
    printf("\nfDiv = %f",fdiv);
    printf("\nMod = %d",mod);
}
Sum = 5
Sub = -1
Mul = 6
iDiv = 0
fDiv = 0.666667
Mod = 1

Modulus Operator: It divides the number and returns the remainder. Modulus operator will work only with integer and character, it will not work with float and double data types.

Advertisement