A very simple C operators, operands and basic mathematics operations
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
To do: To do the basic mathematics operations which demonstrate the C operators, operands and the operations
To show: How to use C operators, operands and basic mathematics operations
/* Simple mathematics calculation */
#include <stdio.h>
/* main() function */
int main(void)
{
/* variables declaration */
int x, y, z;
/* variables initialization - give an initial value to variable*/
/* assign 20 to variable x or put the value of 20 in memory location labeled by x */
x = 20;
y = 2;
/* print some info on the standard output */
printf("Given x = 20, y = 2\n");
printf("\nx / y = %d", x / y);
/* do some calculation */
x = x * y;
y = y + y;
/* print values */
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;
}
Output example:
Given x = 20, y = 2
x / y = 10
x = x * y
y = y + y
New value for x / y = 10
z = 20 * (y / x) = 2
Press any key to continue . . .