1

2
C,;”,.
C;
(9
if( )~else~
switch
for( )~
while( )~
do~while( )
continue
break
goto
return
total=total+limit;
a=3;
func( );
printf(“Hello,world!\n”);

3
{… }
{ []
}
}”

4
goto
~
A
B
A
B
N-S

5
P
A B
P
BA
k
A1 A2 Ai An
k=k2k=k1
k=kn
k=ki
...,..

6
P
A
P
A
A
P
A
P
A,B,A1….An

7
if
if
if (expression)
statement
expr
statement
0
=0
if (x>y)
printf(“%d”,x); expr
statement1 statement2
0 =0?
if (expression)
statement1
else
statement2
if (x>y) max=x;
else max=y;

8
if ( expr1 ) statement1
else if (expr2 ) statement2
else if (expr3 ) statement3
…...
[ else statementn ]
expr1
statemnt1
0
=0
expr2
expr3
statemntnstatemnt3statemnt2
0
0
=0
=0
if (salary>1000) index=0.4;
else if (salary>800) index=0.3;
else if (salary>600) index=0.2;
else if (salary>400) index=0.1;
else index=0;

9
if(a==b&&x==y) printf(“a=b,x=y”);
if(3) printf(“OK”);
if(?a?) printf(“%d”,?a?);
if(x)? if(x!=0)
if(!x)? if(x==0)
,
#include <stdio.h>
main()
{ int x,y;
scanf(“%d,%d”,&x,&y);
if(x>y)
x=y; y=x;
else
x++; y++;
printf(“%d,%d\n”,x,y);
}
Compile Error!

10
if (expr1)
if (expr2) statement1
else statement2
else
if(expr3) statement3
else statement4
if
if
if (expr1)
if (expr2)
statement1
else
statement2
if
if (expr1)
if (expr2)
statement1
else
statement3
if
if (expr1)
statement1
else
if(expr3)
statement3
else
statement4
if
if

11
/*ch4_4.c*/
#include <stdio.h>
main()
{ int x,y;
printf("Enter integer x,y:");
scanf("%d,%d",&x,&y);
if(x!=y)
if(x>y) printf("X>Y\n");
else printf("X<Y\n");
else
printf("X==Y\n");
}
Enter integer x,y:12,23?
X<Y
Enter integer x,y:12,6?
X>Y
Enter integer x,y:12,12?
X==Y

12
{ }elseif
if(……)
if(……)
if(……)
else…...else…...
else…...
if ~ else

13
if (a==b)
if(b==c)
printf(“a==b==c”);
else
printf(“a!=b”);
if (a==b)
{ if(b==c)
printf(“a==b==c”);
}
else
printf(“a!=b”);
if ~ else { }
if ~ else

14
switch( )
{ case E1:
1;
break;
case E2:
2;
break;
…….
case En:
n;
break;
[default:;
break;]
}?
switch
1 2 n…...
E 1 E 2 En default
case
switch

15

break
case
case
……
case?A?:
case?B?:
case?C?,
printf(“score>60\n”);
break;
……..

16
switch(score)
{ case 5,printf(“Very good!”);
case 4,printf(“Good!”);
case 3,printf(“Pass!”);
case 2,printf(“Fail!”);
default,printf(“data error!”);
}
score5
Very good! Good! Pass! Fail! data error!
1

17
/*ch4_5.c*/
#include <stdio.h>
main()
{ int c;
printf("Enter m or n or h or other:");
c=getchar();
switch(c)
{ case 'm',printf("\nGood morning!\n");break;
case 'n',printf("\nGood night!\n"); break;
case 'h',printf("\nHello!\n"); break;
default,printf("\n\n"); break;
}
}
2

18
C
goto if
while
do ~ while
for
gotogoto
goto
goto
….…..

19
4.4 1

20
/*ch5_1.c*/
#include <stdio.h>
main()
{ int i,sum=0;
i=1;
loop,if(i<=100)
{ sum+=i;
i++;
goto loop;
}
printf("%d",sum);
}
sum=0+1
sum==1+2=3
sum=3+3=6
sum=6+4
……
sum=4950+100=5050
if goto

21
while()
expr (0)
(0)
while
while

22
while()
expr (0)
(0)
while
while

23
While

24
while
/*ch5_2.c*/
#include <stdio.h>
main()
{ int i,sum=0;
i=1;
while(i<=100)
{ sum=sum+i;
i++;
}
printf("%d",sum);
}

25
/*ch5_21.c*/
#include <stdio.h>
main()
{ int i=1;
while(i<=10)
{ printf("%d*%d=%d\n",i,i,i*i);
i++;
}
}
1*1=1
2*2=4
3*3=9
4*4=16
5*5=25
6*6=36
7*7=49
8*8=64
9*9=81
10*10=100
1~10

26
do
while();
do
expr
(0)
(0) while
do~while

27
do~whilewhile
expr (0)
(0)
While
do~while

28
for([expr1] ;[ expr2] ;[ expr3])
expr2 (0)
(0)
for
expr1
expr3
for

29
for()
{
}
forexpr1,expr2,expr3
,for(;;)
forwhile
expr1;
while(expr2)
{
expr3;
}
for

30
#include<stdio.h>
main( )
{ int i=0;
for(i=0;i<10;i++)
putchar(‘a’+i);
}
abcdefghij
#include<stdio.h>
main( )
{ int i=0;
for(;i<10;i++)
putchar(‘a’+i);
}
#include<stdio.h>
main( )
{ int i=0;
for(;i<10;)
putchar(‘a’+(i++));
}
#include<stdio.h>
main( )
{ int i=0;
for(;i<10;putchar(‘a’+i),i++);
}

31
0
y
xa a+h a+ih a+(i+1)h b
f(x)
f0r)

32
(1) while()
{ ……
while()
{ ……
}
…...
}
(2) do
{ ……
do
{ ……
}while( );
…...
}while( );
(3) while()
{ ……
do
{ ……
}while( );
…….
}
(4) for( ; ;)
{ ……
do
{ ……
}while();
……
while()
{ ……
}
…...
}

33
i<10
printf
(0)
(0)
i=1
j++
j=1
j<10
(0)
(0)
i++
for(i=1;i<10;i++)
for(j=1;j<10;j++)
printf((j==9)?"%4d\n":"%4d",i*j);

34
break
switch,
break
break switch

35
expr
……
break;
……
(0)
(0)
while do
……
break;
…...
expr
(0)
(0) while

36
expr2
……
break;
…...
(0)
(0)
for
expr1
expr3
switch
expr
1
break;
2
break;
n
break; break;
…...
const 1 const 2 const n default
case

37
expr
……
continue;
……
(0)
(0)
while
(0)
do
……
continue;
…...
expr
(0)
while
expr2
……
continue;
…...
(0)
(0)
for
expr1
expr3
continue