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_single = 0;
int sum_double = 0;
int sum_single = 0;
//float ave_double, ave_single;
while ((num = getchar()) != 0)
{
if (num % 2 == 0)
{
count_double++;
sum_double = sum_double