Simple arithmetic calculations in C

By: Jeffrey Printer Friendly Format    


This simple C program shows simple arithmetic calculations.

#include <stdio.h>
// main() function…
int main( )
{
    // variables declaration
    int  x, y, z;
    // variables initialization, assign 20 to variable x…
    // or put the value of 20 in memory location labeled by x
    x = 20;
    y = 2;
    printf("Given x = 20, y = 2\n");
    printf("\nx / y = %d", x / y);
    // do some basic calculations
    x = x * y;
    y = y + y;
    printf("\nx = x * y");
    printf("\ny = y + y");
    printf("\nNew value for x / y = %d", x / y);
    z = 20 * y / x;
    printf("\nz = 20 * (y / x) = %d\n", z);
   return 0;
}



Ask a Question



Most Viewed Articles (in C )

Latest Articles (in C)

Comment on this tutorial