Arithmetic Operators In C Programming

Arithmetic Operators In C Programming

C programming arithmetic operators; In this tutorial, you will learn in detail about arithmetic operators in the c programming language.

Arithmetic Operators in C

The Arithmetic operators are some of the C Programming Operator, which are used to perform arithmetic operations includes operators like Addition, Subtraction, Multiplication, Division and Modulus.

The below table shows all the Arithmetic Operators in C Programming:

OperatorMeaning of Operator
+addition or unary plus
subtraction or unary minus
*multiplication
/division
%remainder after division (modulo division)

Example 1 – C Programming Arithmetic Operators

// Working of arithmetic operators
#include <stdio.h>
int main()
{
    int a = 9,b = 4, c;
    
    c = a+b;
    printf("a+b = %d \n",c);
    c = a-b;
    printf("a-b = %d \n",c);
    c = a*b;
    printf("a*b = %d \n",c);
    c = a/b;
    printf("a/b = %d \n",c);
    c = a%b;
    printf("Remainder when a divided by b = %d \n",c);
    
    return 0;
}

Output

a+b = 13
a-b = 5
a*b = 36
a/b = 2
Remainder when a divided by b=1

In the above c program, variables a and b are integers. Hence, the output is also an integer. The compiler neglects the term after the decimal point and display output as an integer value.

Don’t get confused, let’s see one next example for a more useful; as shown below:

Example 2 – C Programming Arithmetic Operators using Float values

/* C Program to Perform Division and Modulus on Float data type */

#include<stdio.h> 

int main()
{
 int a = 7, b = 3;
 int integerdiv, modulus;
 float floatdiv;
 
 integerdiv = a / b; // dividing 7 by 3
 modulus = a % b; // calculation the remainder
 floatdiv = (float)a / b; // Converting int to float
 
 printf("Division of two numbers a, b is : %d\n", integerdiv);
 printf("Modulus of two numbers a, b is : %d\n", modulus);

 printf("---------Correct Results is------- \n");
 printf("Division of two numbers a, b is : %f\n", floatdiv);

}

Output

Division of two numbers a, b is : 2
Modulus of two numbers a, b is : 1
---------Correct Results is------- 
Division of two numbers a, b is : 2.333333

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *