哪儿错了????要求定义并调用函数countdigit(number,digit),它的功能是统计整数中某一数字的个数
哪儿错了??????????#include"stdio.h"intmain(void){intcount,digit,in;intrepeat,ri;intcountd...
哪儿错了??????????
#include "stdio.h"
int main(void)
{
int count, digit, in;
int repeat, ri;
int countdigit(int number, int digit);
scanf("%d",&repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%d%d", &in, &digit);
count=countdigit(in,digit);
printf("Number %d of digit %d: %d\n", in, digit, count);
}
}
int countdigit(int number, int digit)
{
int fact,i,a;
fact=0;
if(number<0){
number=-number;
}
i=number;
a=0;
while(i!=0){
a=i%10;
if(digit==a){
fact++;
}
i=(number-a)/10;
}
return fact;
} 展开
#include "stdio.h"
int main(void)
{
int count, digit, in;
int repeat, ri;
int countdigit(int number, int digit);
scanf("%d",&repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%d%d", &in, &digit);
count=countdigit(in,digit);
printf("Number %d of digit %d: %d\n", in, digit, count);
}
}
int countdigit(int number, int digit)
{
int fact,i,a;
fact=0;
if(number<0){
number=-number;
}
i=number;
a=0;
while(i!=0){
a=i%10;
if(digit==a){
fact++;
}
i=(number-a)/10;
}
return fact;
} 展开
展开全部
正确的程序如下:
#include <stdio.h> /* 系统头文件要用<>而不是"" */
int
main(void)
{
int count, digit, in;
int repeat, ri;
int countdigit(int number, int digit);
scanf("%d",&repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%d%d", &in, &digit);
count=countdigit(in,digit);
printf("Number %d of digit %d: %d\n", in, digit, count);
}
}
int
countdigit(int number, int digit)
{
int fact,i,a;
fact=0;
if(number<0){
number=-number;
}
i=number;
a=0;
while(i!=0){
a=i%10;
if(digit==a){
fact++;
}
i=i/10; /* 这里即便你想写(i-a),也应该用循环变量i,但其实之需要i就可以了 */
}
return fact;
}
#include <stdio.h> /* 系统头文件要用<>而不是"" */
int
main(void)
{
int count, digit, in;
int repeat, ri;
int countdigit(int number, int digit);
scanf("%d",&repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%d%d", &in, &digit);
count=countdigit(in,digit);
printf("Number %d of digit %d: %d\n", in, digit, count);
}
}
int
countdigit(int number, int digit)
{
int fact,i,a;
fact=0;
if(number<0){
number=-number;
}
i=number;
a=0;
while(i!=0){
a=i%10;
if(digit==a){
fact++;
}
i=i/10; /* 这里即便你想写(i-a),也应该用循环变量i,但其实之需要i就可以了 */
}
return fact;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询