The C operators, operands and their mathematical operations program example
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: A very simple mathematical operation to show C operators, operands and their operations
To show: How to use the C operator, operation and the operands
// one line comment in program, C++
/* multiple lines comment, C - Program to display
square and square root for the given floating number */
/* for sqrt() function */
#include <math.h>
/*for printf(), scanf() & other standard formatted i/o */
#include <stdio.h>
int main(void)
{
/* variable named x with floating-point data type */
float x;
/* standard output */
printf("\nEnter one positive number (1, 2, 3. . .): ");
/* standard input, read and store */
/* scanf("%f", &x); */
/* reserve 4 bytes for float */
scanf_s("%f", &x, 4);
printf("\nx = %f ", x);
printf("\nSquare for x is = %f", x * x);
// sqrt() is the predefined function, defined in math.h header file
printf("\nSquare root for x is = %f\n", sqrt(x));
return 0;
}
Output example:
Enter one positive number (1, 2, 3. . .): 100
x = 100.000000
Square for x is = 10000.000000
Square root for x is = 10.000000
Press any key to continue . . .