7.1
//编写一个程序读取输入,读到#字符停止,然后报告读取的空格数
//换行符数和所有其他字符的数量
#include <stdio.h>
#define STOP '#'
#define SPACE ' '
int main(void)
{
char ch;
int lines=1;
int spaces=0;
int others=0;
while ((ch = getchar()) != STOP)
{
if (ch == SPACE)
spaces++;
if (ch == '\n')
lines++;
else
others++;
}
printf("There are %d lines, %d spaces, %d others.", lines, spaces, others);
return 0;
}
7.2
//编写一个程序读取输入,遇到#停止
//程序要打印每个输入的字符以及对应的ASCII码(十进制),一行8个
#include <stdio.h>
#define NUM 8
#define STOP '#'
int main(void)
{
char ch;
int count=0;
while ((ch = getchar()) != 'STOP')
{
count++;
putchar(ch);
printf(":%d ", ch);
if (count % 8 == 0)
printf("\n");
}
printf("Job Down!");
return 0;
}
7.3
程序错误,不知道哪里有问题。。。
先记录以后查找。。。
//编写一个程序,读取整数知道用户输入0
//输入结束后,程序应报告用户输入的偶数、平均数、奇数、平均数个数
#include <stdio.h>
int main(void)
{
char num;;
int count_double = 0;
int count_si

本文档记录了C Primer Plus第六版第七章的编程练习答案,包括7.1至7.9节的部分题目。由于部分题目复杂,如7.7、7.8和7.9,作者提到需要参考其他资料进行解答或暂未完成。
最低0.47元/天 解锁文章
2500

被折叠的 条评论
为什么被折叠?



