自己学习过程中编写的,仅供参考,如有错误,欢迎评论区指正!
01
#include <stdio.h>
int main(void)
{
int space = 0, n = 0, other = 0;
char ch;
while ((ch = getchar()) != '#')
{
if (ch == ' ')
space++;
else if (ch == '\n')
n++;
else
other++;
}
printf("space=%d, n=%d, other=%d\n", space, n, other);
return 0;
}
02
#include <stdio.h>
int main(void)
{
int count = 0;
char ch;
while ((ch = getchar()) != '#')
{
if (count++ % 9 == 0)
putchar('\n');
else if (ch == '\n')
printf("'\\n',%-3d ", ch);
else if (ch == '\t')
printf("'\\t',%-3d ", ch);
else
printf("%c,%-3d ", ch, ch);
}
return 0;
}
03
#include <stdio.h>
int main(void)
{
double ave_ou, ave_ji;
int num, sum_ou, sum_ji, count_ou, count_ji;
sum_ji = sum_ou = count_ji = count_ou = 0;
printf("请输入数字:");
while (scanf("%d", &num) == 1 && num)
{
if (num % 2 == 0)
{
count_ou++;
sum_ou += num;
}
else
{
count_ji++;
sum_ji += num;
}
printf("请继续输入整数(输入0退出程序):");
}
printf("偶数个数为:%d, 偶数平均值为:%.2lf\n", count_ou, ave_ou);
printf("奇数个数为:%d, 奇数平均值为:%.2lf\n", count_ji, ave_ji);
printf("程序结束\n");
return 0;
}
04
#include <stdio.h>
int main(