C primer Plus Chap 07
C primer Plus Chap 07
C primer Plus 第七章代码与练习记录。
C语言控制语句:分支和跳转
- fx5.c输出结果:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <stdio.h>
#include <ctype.h>
int main(void)
{
int num;
for(num=1; num<=11; num++)
{
if(num % 3 == 0)
putchar('$');
else
putchar('$');
putchar('#');
putchar('%');
}
putchar('\n');
return 0;
}1
$#%$#%$#%$#%$#%$#%$#%$#%$#%$#%$#%
- fx6.c输出结果:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <stdio.h>
int main(void)
{
int i=0;
while(i<3)
{
switch(i++)
{
case 0:printf("fat");
case 1:printf("hat");
case 2:printf("cat");
default:printf("oh no!");
}
putchar('\n');
}
return 0;
}1
2
3fathatcatoh no!
hatcatoh no!
catoh no! - fx7.c输出结果:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <stdio.h>
int main(void)
{
char ch;
int lc=0;
int uc=0;
int oc=0;
while((ch=getchar())!='#')
{
if(ch>='a' && ch<='z')
lc++;
else if(ch>='A' && ch<='Z')
uc++;
else
oc++;
}
printf("%d lowercase, %d uppercase, %d other\n", lc, uc, oc);
return 0;
}1
2
3
4
5
6
7
8
9
10
11a
b
c
A
B
C
1
2
3
#
3 lowercase, 3 uppercase, 12 other
C primer Plus Chap 07
https://ywmy.xyz/2022/05/14/C-primer-Plus-Chap-07/