0

大家好,我是 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;
    }
  }
}
4

1 回答 1

1

Seems to me its the 2D array split that gets too large for your stack. You could probably try to allocate it dynamically as suggested here: how to deal with large 2D arrays

于 2012-12-15T21:06:58.157 回答