Illustrate the use of various arithmetic operators - C Operator

C examples for Operator:Arithmetic Operator

Description

Illustrate the use of various arithmetic operators

Demo Code

#include <stdio.h>

int main (void)
{
    int a = 100;/* www  .j a va 2  s.co  m*/
    int b = 2;
    int c = 25;
    int d = 4;
    int result;

    result = a - b;     // subtraction
    printf ("a - b = %i\n", result);

    result = b * c;     // multiplication
    printf ("b * c = %i\n", result);

    result = a / c;     // division
    printf ("a / c = %i\n", result);

    result = a + b * c;     // precedence
    printf ("a + b * c = %i\n", result);

    printf ("a * b + c * d = %i\n", a * b + c * d);


    float e = 25.0;
    float f = 2.0;

    printf("6 + a / 5 * b = %i\n", 6 + a / 5 * b);
    printf("a / f * b = %i\n", a / f * b);
    printf("c / e * d = %f\n", c / e * d );
    printf("-a = %i\n", -a);

    return 0;
}

Related Tutorials