C语言:输入一组数,统计其中奇数和偶数的个数,知道遇到回车为止.怎样写啊,1楼的不行,2楼的有4个错误:--------------------Configuration:6(3) - Win32 Debug--------------------Compiling...6(3).cC:\Documents and Setti

来源:学生作业帮助网 编辑:作业帮 时间:2024/03/29 02:45:06
C语言:输入一组数,统计其中奇数和偶数的个数,知道遇到回车为止.怎样写啊,1楼的不行,2楼的有4个错误:--------------------Configuration:6(3) - Win32 Debug--------------------Compiling...6(3).cC:\Documents and Setti

C语言:输入一组数,统计其中奇数和偶数的个数,知道遇到回车为止.怎样写啊,1楼的不行,2楼的有4个错误:--------------------Configuration:6(3) - Win32 Debug--------------------Compiling...6(3).cC:\Documents and Setti
C语言:输入一组数,统计其中奇数和偶数的个数,知道遇到回车为止.怎样写啊,
1楼的不行,2楼的有4个错误:--------------------Configuration:6(3) - Win32 Debug--------------------
Compiling...
6(3).c
C:\Documents and Settings\Administrator\桌面\6(3).c(353) :error C2143:syntax error :missing ';' before 'type'
C:\Documents and Settings\Administrator\桌面\6(3).c(354) :error C2065:'i' :undeclared identifier
C:\Documents and Settings\Administrator\桌面\6(3).c(358) :error C2065:'a' :undeclared identifier
C:\Documents and Settings\Administrator\桌面\6(3).c(362) :error C2065:'b' :undeclared identifier
Error executing cl.exe.
6(3).obj - 4 error(s),0 warning(s)

C语言:输入一组数,统计其中奇数和偶数的个数,知道遇到回车为止.怎样写啊,1楼的不行,2楼的有4个错误:--------------------Configuration:6(3) - Win32 Debug--------------------Compiling...6(3).cC:\Documents and Setti
/***以下我觉得自己算写得比较好的了.你可以输入任意多个字符,而且有非数字字符等各种错误输入也不会影响统计.希望对你有所帮助.**/
/***
** 输入一组数,统计奇数和偶数的个数.
**/
#include
int main(void){
char ch;
int num;
int even_num = 0;//纪录偶数个数
int old_num = 0;//奇数个数.
int other = 0;//其它字符个数
printf("请输入一组数字(回车则表示结束!):\n\t");
do{
do{
ch = getchar();
}while(ch==' ');
if(ch=='\n')break;
else if(ch>='0'&&ch0){
printf("\t同时以上输入了:%2d个非数字字符\n",other);
}
return 0;
}///main:
/***以下为输入输出结果示列:
请输入一组数字(回车则表示结束!):
1 2 3 # 4 5 6
以上输入的数中,奇数有:3 个,偶数有:3 个
同时以上输入了:1个非数字字符
----------------------------------------
请输入一组数字(回车则表示结束!):
1 2 3 4 5 6 7 8
以上输入的数中,奇数有:4 个,偶数有:4 个
**/