gpt4 book ai didi

C++ 程序崩溃

转载 作者:行者123 更新时间:2023-11-28 07:50:32 24 4
gpt4 key购买 nike

大家好,我是 C++ 的新手,所以我正在编写一个程序,它工作正常,但有一个问题。每次我输入大于 100 的数字时,我的程序都会崩溃,我不知道为什么。谁能帮帮我?

程序代码:

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
int i = 10;

while(i > 0)
{
i--;

int b = 0, c = 1, d = 0, e, number, how = 0, number1, start, to, number2, split1, split2, mass, start1 = 0, start2 = 0, number3, how1, number4, number5;

cout << "\nIveskite skaiciu \n";
cin >> number;
cout << "\n";

number1 = number;

while(number1 > 0)
{
number1 = number1 / 10;
how = how + 1;
}

how1 = how - 1;
start = pow(10, (how - 1));
to = pow(10, how);
mass = to - start;
number2 = start - 1;
int split[mass][mass], numbers[mass], ok[mass];

while(start1 < mass)
{
start1++;

e = number2 + start1;

numbers[start1] = e;
split[start1][0] = e;
}

while(start2 < mass)
{
start2++;

number3 = numbers[start2];

d = 0;
b = 0;
c = 1;

while(d <= how1)
{
d++;

split1 = number3%10;
split2 = number3 / 10;
number3 = split2;
split[start2][d] = split1;
number4 = b + split[start2][d];
b = number4;
number5 = c * split[start2][d];;
c = number5;

}

if(number4 == number5)
{
ok[mass] = numbers[start2];

cout << number4 << " " << number5 << " >" << ok[mass] << endl;
}
}
}

最佳答案

在我看来,二维数组拆分对于您的堆栈来说太大了。您可能会尝试按照此处的建议动态分配它:how to deal with large 2D arrays

关于C++ 程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13895990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com