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

    • Running Tests in Parallel with Selenium Grid
    • Advanced Selenium Features
    • Locating Web Elements
    • Running the Test Script
    • Writing Your First Selenium Test Script
    • Getting Started with Selenium Automation Testing
    • Setting Up the Environment
    • How can you monitor the Quality Assurance Audit?
    • Leveraging LambdaTest with Appium 2.0
    • Appium 2.0 Plugins ListAppium 2.0 Plugins
    • Touch Actions and Multi-Touch Actions
    • Changes in Drivers and Classes
    • Appium Inspector
    • Capabilities in Appium 2.0
    • Appium 2.0 Driver ListAppium 2.0 Driver Installation & Management
    CyberLink Multimedia Software

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com