ARITHMETIC OPERATORS IN C

Maha

 

 

Arithmetic Operators In C

  • Arithmetic operators in C are used to perform like a mathematical calculations on numerical values. There are commonly used arithmetic operators in C.
  • Operators are symbols like addition, subtraction, and comparison with the programming languages. Here are some common operators in various programming languages along with their examples.

Arithmetic Operators Are:

+  Addition
-   Subtraction
*  Multiplication
/   Division
% Modulo


Example For Addition(+) Operator:

Program 1:

 
  #include<stdio.h>
  int main() {
    int a,b;
    a=10;
    b=5;
    int c;
    c=a+b;
    printf("The sum of a and b values is:%d",c);
  }


Output:

   
  The sum of a and b values is:15


Program 2:

  
  #include<stdio.h>
  int main() {
    int a=6, b=5;
    printf("Addition:%d",a+b);    
  }


Output:


  Addition:11


Example For Subtraction(-) Operator:

Program 1:


  #include<stdio.h>
  int main() {
    int a,b;
    a=10;
    b=5;
    int c;
    c=a-b;
    printf("The value of c :%d",c);
  }


Output:


  The value of c :5


Program 2:

  
  #include<stdio.h>
  int main() {
    int a=6,b=5;
    printf("Subtraction:%d",a-b);    
  }


Output:


  Subtraction:1


Example For Multiplication(*) Operator:

Program 1:

  
  #include<stdio.h>
  int main() {
    int a,b;
    a=10;
    b=5;
    int c;
    c=a*b;
    printf("The value of c:%d",c);
  }


Output:


  The value of c:50



Program 2:

  
  #include<stdio.h>
  int main() {
    int a=6,b=5;
    printf("Multiplication:%d",a*b);
  }



Output:


  Multiplication:30



Example For Division(/) Operator:

Program 1:


  #include<stdio.h>
  int main() {
    int a,b;
    a=10;
    b=5;
    int c;
    c=a/b;
    printf("The value of c:%d",c);
  }


Output:


  The value of c:2



Program 2:


  #include<stdio.h>
  int main() {
    int a=15,b=5;
    printf("Division:%d",a/b);
  }
  


Output:


  Division:3



Example For Modulus(%) Operator:

Program 1:


  #include<stdio.h>
  int main() {
    int a,b;
    a=5;
    b=2;
    int c;
    c=a%b;
    printf("The value of c:%d",c);
   }



Output:


  The value of c:1


Program 2:


  #include<stdio.h>
  int main() {
    int a=12,b=5;
    printf("Modulo:%d",a%b);    
  }


Output:


  Modulo:2




More topic in C

Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send