鱼C论坛

 找回密码
 立即注册
查看: 4230|回复: 3

c语言39题

[复制链接]
发表于 2018-1-11 18:50:35 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
39.编写程序,输入一个整数,统计并输出该数中数字‘2’的个数。要求定义并调用函数countdigit(number,digit),它的功能是统计整数number 中数字digit的个数。例如countdigit(10090,0)的返回值是3。
11.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-1-11 19:16:07 | 显示全部楼层
2018-01-11_191400.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-1-15 10:29:41 | 显示全部楼层
#include<stdio.h>
#include<math.h>
int countdigit(int x,int y);
int  main(void)
{
int x,c;
printf("请输入一个整数:");
scanf("%d",&x);
c=countdigit(x,2);
printf("总共有%d个\n",c);
return 0;
}
int icount;
icount = 0;
while(x%10 != 0);`
{
if(x%10==y)
{
icount += 1;
}
x=x/10;
}
return icount;
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-1-15 10:30:25 | 显示全部楼层
C:\Users\404\Desktop\Cpp1.cpp(14) : error C2501: 'icount' : missing storage-class or type specifiers
C:\Users\404\Desktop\Cpp1.cpp(14) : error C2086: 'icount' : redefinition
C:\Users\404\Desktop\Cpp1.cpp(15) : error C2143: syntax error : missing ';' before 'while'
C:\Users\404\Desktop\Cpp1.cpp(15) : error C2018: unknown character '0x60'
C:\Users\404\Desktop\Cpp1.cpp(16) : error C2447: missing function header (old-style formal list?)
C:\Users\404\Desktop\Cpp1.cpp(23) : error C2143: syntax error : missing ';' before 'return'
Error executing cl.exe.
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-27 18:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表