这个怎么改才对啊

来源:百度知道 编辑:UC知道 时间:2024/05/30 09:23:44
输入五位一下的数字,判断数字中0个数的和。如:10101 0 的个数为2
出来只有一个错 貌似在 void px1(int p=0,int n)中,但不晓得哪里错了
各位高手帮帮忙`
#include<stdio.h>
#include<conio.h>
void main()
{
long int n;
int p;
printf("Please input n:\n");
scanf("%1d",&n);
if(n>9999)
{
p=px1(p);
}
else if(n>999)
{
p=px2(p);
}
else if(n>99)
{
p=px3(p);
}
else if(n>9)
{
p=px4(p);
}
else
{
p=0;
}
printf("%d",p);
getch();
}
void px1(int p=0,int n)
{
ten_thousand=n/10000;
thousand=(n-ten_thousand*10000)/1000;
if(thousand==0)
p=p+1;
else
p=px2(p);
return p;
}
void px2(int p=0,int n)
{
thousand=n/1000;
hundred=(n-thousand*1000)/100;
if(hundred==0)

你的代码,函数在使用前没有声明;
算法也比较烦琐,我重新给你编了个
不知道行不行~!

#include <stdio.h>
int main()
{
char a[6];
int n=0;
printf("Please input n:\n");
gets(a);
char *p = &a[0];
while(*p != '\0')
{
if(*p == '0')
n++;
p++;
}
if(n>5)
printf("Input Error\n");
else
printf("%d\n",n);
return 0;
}

void main()
{
long int n;
int p;
printf("Please input n:\n");
scanf("%1d",&n); <-----这个%1d 是什么概念啊?