TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

C Tutorials

C Arithmetic Operators

Overview

In this tutorial, we will learn about different C Arithmetic Operators
with some examples.

C Arithmetic Operators

 

Arithmetic Operation Arithmetic Operator Description Examples
Addition + The addition operator adds the two operands sum = a + b
Subtraction – Subtracts the second operand from the first operand diff = a – b
Multiplication * The multiplication operator multiplies the two operands product = a * b
Division / The division operator divides the numerator by the denominator div = a/b
Modulus % Computes the remainder of the integer division rem= a%b

Syntax

The general form of the C arithmetic expression is as follows:

<variable_to_store> = operand1 arthOperator operand2 ;

For example, to add two numbers and store the value of the arithmetic
expression to a variable sum:

sum = 10 + 5 ;

To add two variables:

sum = number1 + number2 ;

where sum, number1, and number2 are variables.

Sample C Program

 

/************************************
* C Arithmetic Operators
* Filename: arithmetic.c
* C Arithmetic Operators Demo
* program.
* C Tutorials - www.TestingDocs.com
**************************************/
#include<stdio.h>

int main()
{
 //Declare two variables
 int a=22,b=5;
 int sum,difference,product,rem;
 double div;

 sum = a + b; // addition
 difference = a - b; // subtraction
 product = a*b; // product
 div = a/b; // divide
 rem = a%b; // get remainder
 // Print Statements
 printf ("Sum = %d \n", sum);
 printf ("Difference = %d \n", difference);

 printf ("Product = %d \n", product);
 printf ("Division = %lf \n", div);
 printf ("Modulus = %d \n", rem);

 printf ("\nC Tutorials - www.TestingDocs.com\n");
 return 0;
} // end main

C Arithmetic Operators

Program Output

Sum = 27
Difference = 17
Product = 110
Division = 4.000000
Modulus = 2

C Arithmetic Operators Output

Related Posts

C Language Characteristics

C Tutorials /

C Language Characteristics

C Source Code .c File

C Tutorials /

C Program Files & Formats

GNU Compiler Collection GCC

C Tutorials /

C Compilers

C Pointers

C Tutorials /

C Pointers

C Tutorials /

C Two-Dimensional Arrays

‹ C Program Structure› Free IDEs for C Development

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com