Latest courses

Arithmetic Operators in C

In this example, You learn about arithmetic operators in C. Also, Understand the math operators and operands. I'll share the basic arithmetic operations program in which we do calculations on two operands.

Let's understand the terms operators and operands.
Operator - This specifies the operation on data that contains some value.
Operand - The data on which operator works is called operand.

Types of Arithmetic Operators in C

  1. Addition 
  2. Subtraction
  3. Multiplication
  4. Division
  5. Modulus 
C Arithmetic Operators


You have doubt in the above paragraph then I shared a table below which clear your all doubts and it helps to understand about operators.

Arithmetic Operators Operation Example 
                + Addition 15 + 3 = 18
                 -                
 Subtraction 15 - 3 = 12
                  Multiplication  15 * 3 = 45
                 / Divison 15 / 3 = 5
                 % Modulus 15 % 3 = 0 

Some of them know about the difference in division and modulus but we revisit this. Now when we use division(/) operator with operands then it gives results as quotient and when we use modulus(%) operator with operands then the result is remainder. Example as mention above table.

Now you have great knowledge about the arithmetic operators and from examples of the above table. Below I share arithmetic operators in c with example program. In this program, you have to enter two integer numbers and then c arithmetic operators work on operands.

#include<stdio.h>  
int main()
 { 
   int a,b;
    printf(" \n Enter two numbers");
    scanf("%d%d",&a,&b);
    printf("\n Addition of a and b: %d \t",(a+b));
    printf("\n Subtraction of a and b: %d \t",(a-b));
    printf("\n Multiplication of a and b: %d \t",(a*b));
    printf("\n Divide of a and b: %d \t",(a/b));
    printf("\n Modulus of a and b: %d \t",(a%b));
   return 0;
 }


The program asks the user for two operands and then to perform arithmetic operations in C on numbers.



   Enter Two Numbers 15 3 
   Addition of a and b: 18
   Subtraction of a and b: 12
   Multiplication of a and b: 45
   Division of a and b: 5
   Modulus of a and b: 0
   

You have any problem with these arithmetic operators in C. Do not hesitate and write your problem in the comment box. I will support your problem.


Happy Coding ๐Ÿ˜Š

No comments:

If you have any doubts, Please let me know

Powered by Blogger.