题目描述
定义一个函数check(n,d),它送回一个结果。如果数字d在整数n的某位中出现,则送回“1”,否则送回“0”。例如check(3256,2)的返回值=1,check(1725,3)的返回值=0。编写完整程序效果如下
输入
41632,6
输出
The digit 6 is in data 41632
样例输入
25348,7
样例输出
The digit 7 is not in data 25348
#include "stdio.h"
int check(int n,int d);
int main()
{
int num1,num2;
printf("Enter n,d:");
scanf("%d,%d",&num1,&num2);
if(check(num1,num2)==1)
printf("The digit %d is in data %d\n",num2, num1);
else
printf("The digit %d is not in data %d\n",num2,num1);
}
int check(int n,int d){
int result = 0;
if(n == 0){
result++;
}
while(n != 0){
if(n % 10 == d){
result++;
}
n = n / 10;
}
return result;
}