对问答区Q7496881编写的程序与预期不符

原问题: C++启蒙题目求解答,在线坐等采纳。-编程语言-CSDN问答 CSDN问答为您找到C++启蒙题目求解答,在线坐等采纳。相关问题答案,如果想了解更多关于C++启蒙题目求解答,在线坐等采纳。 c++、c语言 技术问题等相关问答,请访问CSDN问答。 https://ask.csdn.net/questions/7496881
我的代码:

#include <iostream>
using namespace std;
#define LIMIT 7

int main()
{
    int input;
    scanf("%d", &input);
    // input = 100000;

    int count = 0;
    int index = 0;
    char n1[LIMIT] = {0};
    char n2[LIMIT] = {0};

    for (int i = 1; i <= input; i++)
    {

        itoa(i, n1, 10);
        itoa(i, n2, 8);
      

        char temp;
        index = 0;
        while (index < LIMIT)
        {
            if (n1[index] == '7')
            {
                count++;
                // printf("%s\n",n1);
                break;
            }
            if (n2[index] == '7')
            {
                count++;
                //  printf("O\t%s\n",n2);
                break;
            }
            index++;
        }
    }
    printf("%d", count);
}
}

原问题中输入100000会返回30555,我输入100000会返回69445
不知道为什么,感觉是itoa用的不对?

输出不一样,肯定用得不对。

首先有数重的,7(10)->7(8),这个是算一个数;其次数字中只要有7就只算一个数,而不是一个7算一个。