- ..clause 1..: Calculation and result display
- ..clause 2..: Four rules of arithmetic operator
- ..clause 3..: Complex expression
Though the expression called 100+200=300 was displayed on the screen in the foregoing paragraph
The numerical value called 100,200,300 was arranged directly at that time.
In a word, Man was previously calculating the part of the answer called 300.
However, there is with this no computer-aided meaning.
Such a calculation should make the computer put it.
In C language, only because the expression is described to calculate, it is settled.
The following program is an example of making the computer put the calculation of 100+200.
The execution result of this program becomes as follows.int main(void) { 100+200; }
The result is not displayed on the screen.
Then, how do do to display the result of the calculation?
[ The computer is obstinate and obedient ].
The computer is obstinate and obedient in this manner.
In short, though all the given instructions are obediently executed on the street
Besides, it has obstinacy of not giving the full monty.
Though it is natural to display the result when calculating from man
The computer doesn't have such consideration at all.
Actually, it is also possible to pass the expression, and to convert the numerical result of the expression into the figure.
The following program is an example that calculates 100+200 and displays.
The execution result of this program becomes as follows.#include <stdio.h> int main(void) { printf("%d\n",100+200); return 0; }
Being passed to the printf function : the hope of you note it by this program.
300
Of course, other calculations are also possible though it added in the preceding clause (addition).
A basic operator of C language is as shown in the following table.
| Sign in C language | Sign in mathematics | Function |
|---|---|---|
| + | + | Addition(addition) |
| - | - | Subtraction(subtraction) |
| * | × | Multiplication(multiplication) |
| / | ÷ | Division(dividing calculation) |
| % | … | Surplus calculation(The dividing calculation too much. ) |
The usage of the operator is quite the same as mathematics.
The following program is an example that uses the operator introduces here in general.
The execution result of this program becomes as follows.#include <stdio.h> int main(void) { printf("%d\n",10 + 3); printf("%d\n",10 - 3); printf("%d\n",10 * 3); printf("%d\n",10 / 3); printf("%d\n",10 % 3); return 0; }
The part where it wants you to pay attention by this program
13
7
30
3
1
The result of the integer calculation becomes not the half-adjust but a round-down.
Because when you reversely calculate the number quotient × divided when rounding it off
From ....former.. drinking.. number to it is as a result because contradiction of largeness is caused that is [wari]
[ Bargain calculator and high-level calculator ]
Actually, this calculation is an easy method of distinguishing a bargain calculator and a high-level calculator.
You also : with a calculator on hand Calculate with 10÷3×3.
Though it was displayed in the high-level calculator that the author has as ten
In the calculator in the hundred-yen store It was displayed as 9.9999999.
Seem to pursue the calculation on the way and to display it accurately in a high-level calculator.
Being possible to calculate by C language is not only a simple expression.
The execution result of this program becomes as follows.#include <stdio.h> int main(void) { printf("%d\n",(1 + 100) * 100 / 2); return 0; }
Also in C language, the priority level in the expression is the same as mathematics.
5050