C 用于检查一个数字是否包含在另一个数字中的程序

C 用于检查一个数字是否包含在另一个数字中的程序,c,C,我做了一个程序,可以检查一个数字是否包含在另一个数字中,例如: 1234 234 1234包含234吗?对打印真实 1234 943 1234包含943吗?不打印错误 我的问题是我不知道如何打印false,我有一个有问题的if,那么我如何仅在不包含数字的情况下打印false?如果程序打印为真,那么它也打印为假,那么我如何才能使它仅在不包含数字的情况下打印为假? 我的代码: #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #incl

我做了一个程序,可以检查一个数字是否包含在另一个数字中,例如: 1234 234 1234包含234吗?对打印真实 1234 943 1234包含943吗?不打印错误 我的问题是我不知道如何打印false,我有一个有问题的if,那么我如何仅在不包含数字的情况下打印false?如果程序打印为真,那么它也打印为假,那么我如何才能使它仅在不包含数字的情况下打印为假? 我的代码:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
int main() {
    int firstnumb, tobechecked, numberofdigits = 0, hezka;
    scanf("%d %d", &firstnumb, &tobechecked);
    numberofdigits = log10(tobechecked) + 1;
    hezka = pow(10, numberofdigits);
    while (firstnumb > 0) {
        if (firstnumb % hezka == tobechecked) {
            printf("true");
        }
        firstnumb = (firstnumb / 10);
    }
    printf("false");

}
\define\u CRT\u SECURE\u NO\u警告
#包括
#包括
int main(){
int firstnumb,tobechecked,numberofdigits=0,赫兹卡;
scanf(“%d%d”,&firstnumb,&tobecheck);
numberofdigits=log10(待检查)+1;
赫兹卡=功率(10,位数);
while(firstnumb>0){
if(firstnumb%hezka==tobechecked){
printf(“真实”);
}
firstnumb=(firstnumb/10);
}
printf(“假”);
}
编辑:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
int main() {
    int firstnumb, tobechecked, numberofdigits = 0, hezka , result = 0;
    scanf("%d %d", &firstnumb, &tobechecked);
    numberofdigits = log10(tobechecked) + 1;
    hezka = pow(10, numberofdigits);
    while (firstnumb > 0) {
        if (firstnumb % hezka == tobechecked) {
            result = 1;
        }
        firstnumb = (firstnumb / 10);
    }
    if (result) {
        printf("true");
    }
    else {

        printf("false");
    }

}
\define\u CRT\u SECURE\u NO\u警告
#包括
#包括
int main(){
int firstnumb,tobechecked,numberofdigits=0,hezka,result=0;
scanf(“%d%d”,&firstnumb,&tobecheck);
numberofdigits=log10(待检查)+1;
赫兹卡=功率(10,位数);
while(firstnumb>0){
if(firstnumb%hezka==tobechecked){
结果=1;
}
firstnumb=(firstnumb/10);
}
如果(结果){
printf(“真实”);
}
否则{
printf(“假”);
}
}

您可以计算找到要检查的号码的时间。然后,在while循环之后,使用该计数确定打印的是真还是假

int count = 0;

while (firstnumb > 0) {
    if (firstnumb % hezka == tobechecked) {
        count++;
    }
    firstnumb = (firstnumb / 10);
}

if (count == 0)
{
    printf("false");
}
else
{
    printf("true");
}

123123
123
将打印两次
true
。这是预期的行为吗?@Cid你确定吗?我又查了一遍,它给了我一次真实的机会啊,也许不是,那么