※スタイルシート未対応ブラウザではレイアウトを正確に再現できません。
> | advanced by | contents  | that returns in <
< [modosusu] > Color magazine monochrome light and shade   font predetermined, Gothic Ming-style type longhand   size Konaka large   standard

Basic calculation

1. ..clause 1..: Calculation and result display
2. ..clause 2..: Four rules of arithmetic operator
3. ..clause 3..: Complex expression

[1] Calculation and result display

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.

``` int main(void)
{
100+200;
}
```
The execution result of this program becomes as follows.

The result is not displayed on the screen.
This is natural, and the program ahead is written only to calculate 100+200.
Display the result of the calculation because of not being written at all.

[ 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.
Then, how do do to display the result of the calculation?
Of course, use the printf function for the display to the screen.
The character is displayed by the printf function, and it knows the method that converts the numerical value into the figure and displays.

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.

```
#include <stdio.h>

int main(void)
{
printf("%d\n",100+200);
return 0;
}
```
The execution result of this program becomes as follows.

300
Being passed to the printf function : the hope of you note it by this program.
It is a point said It is not an expression called 100+200 but it is a result 300.
The part of 100+200(Regardless of the printf function) is calculated without permission, and converted into 300.
And, that 300 was converted into the figure further, and to the screen It was displayed as 300.

It returns to contents.

[2] Four rules of arithmetic operator

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.
- - Subtraction(subtraction)
* × Multiplication(multiplication)
/ ÷ Division(dividing calculation)
% Surplus calculation(The dividing calculation too much. )
I think that I notice a sign different from mathematics might used when this table is seen.
Because there are neither × nor ÷ in the sign expressible with the keyboard of a general computer
It doesn't limit to C language, and another sign is used in a lot of programming languages.

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.

```
#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 execution result of this program becomes as follows.

13
7
30
3
1
The part where it wants you to pay attention by this program
The numerical result of 10/3(10÷3) It is displayed as three.
Though being displayed as 3.3333333 is usual if it is a calculator
The result becomes an integer because it calculates any numerical value here as an integer, too.

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.

It returns to contents.

[3] Complex expression

Being possible to calculate by C language is not only a simple expression.
Even if it is a more complex expression, it is possible to calculate without trouble.
The following program is an example of officially calculating the total to 1-100.
```
#include <stdio.h>

int main(void)
{         printf("%d\n",(1 + 100) * 100 / 2);
return 0;
}
```
The execution result of this program becomes as follows.

5050
Also in C language, the priority level in the expression is the same as mathematics.
Multiplication and division are previously calculated from addition and the subtraction.
It is also quite the same as mathematics to apply () to change the priority level.
It is different in C language though is used.
Only the sign is used.

It returns to contents.

< - It is advanced -> | in | head that returns  to returning  next |.