
去掉continue和goto语句,结果同上
//q
//c
//h
//b
#include<stdio.h>
int main()
{
char ch;
while ((ch = getchar()) != '#')
{
if (ch != '\n')
{
printf("step 1\n");
if (ch == 'b')
break;
else if (ch != 'c')
{
if (ch != 'h')
printf("step 2\n");
printf("step 3\n");
}
}
}
printf("done\n");
return 0;
}
#define _CRT_SECURE_NO_WARNINGS 10
#include<stdio.h>
int main()
{
char ch;
int count_space = 0;
int count_linkbreak = 0;
int count_other = 0;
while ((ch = getchar()) != '#')
{
if (ch == ' ')
{
count_space++;
}
else if (ch == '\n')
{
count_linkbreak++;
}
else
{
count_other++;
}
}
printf("spaces is %d,linkbreak is%d,other is %d\n", count_space, count_linkbreak, count_other);
return 0;
}
编写一个程序,读取整数直到用户输入0。
输入结束以后,程序应报告用户输入的偶数(不包括0)个数、这些偶数的平均值、输入的奇数个数及其奇数的平均数。
#define _CRT_SECURE_NO_WARNINGS 10
#include<stdio.h>
int main()
{
int i;
int sum_odd = 0;
int sum_even = 0;
int odd = 0;//奇数
int even = 0; //偶数
printf("输入整数,以0为结尾\n");
while (scanf("%d", &i)==1)
{
if (i == 0)
break;
if (i % 2 != 0)
{
odd++;
sum_odd = sum_odd + i;
}
else
{
even++;
sum_even = sum_even + i;
}
}
printf("odd is %d,even is %d\n", odd,even);
printf("偶数平均值%d(不包括0),奇数平均值%d\n", (sum_even /even), (sum_odd /odd));
return 0;
}
1万+

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



