Hello, everyone, to start learning it today - cycle structure
Wherein the loop structure comprises:
- for statement
- while statement
- do whlie statement
Second, also you need to get:
- break statement
- continue Statement
Well start today's study notes:
For statement:
for(循环变量初值;条件表达式;循环变量体增值)
Equivalent to
for (;条件表达式;)
{
循环体
循环变量增值
}
Loop body can be written in different forms according to the meaning of the questions, which require analysis tool has to ask friends ~
Example: chickens and rabbits with cage problem: a total of 100 chickens and rabbits, a total of 274 feet, and besought chickens, rabbits have how many?
Analysis: The relationship between chickens and rabbits for the chicken :( set only for the x, y is the only rabbit)
x + y = 100
2 x 4 + y = 278
#include <stdio.h>
int main ()
{
int x,y;
for(x=1;x<100;x++)
{
y = 100 - x;
if (x * 2 + y * 4 == 274 )
printf("鸡有:%d只,兔有:%d只\n", x,y);
}
}
This program is thinking -
knock when the code must be careful carefully, open your eyes Atlanta card position, do not sign anything less (like me)!
Thank you see here! Goodnight everybody! see u tomorrow!
Tomorrow add some examples, along with "well-informed"