Programming Tutorials

Simple arithmetic calculations in C

By: Jeffrey in C Tutorials on 2012-03-16  

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;
}





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in C )

Latest Articles (in C)