c 程序在linux运行不了,C ++程序在Linux上运行完美,但无法在Windows上运行(示例代码)...

我有这个代码在Ubuntu 16.04.3 LTS上完美运行。但是当我通过Windows上的Codeblock构建并运行它时。这只是CRASH。我不知道我错了什么,我怎么能解决这个问题。我写的很多C ++程序可以在Linux上运行但在Windows上运行CRASH就像那样。

非常感谢你们的帮助!

#include

using namespace std;

int d = 1;

void topRight(int [999][999], int, int, int, int);

void bottomLeft(int [999][999], int, int, int, int);

void topRight(int a[999][999], int x1, int y1, int x2, int y2) {

for (int i=x1;i<=x2;i++) a[y1][i]=d++;

for (int j=y1+1;j<=y2;j++) a[j][x2]=d++;

if (x2-x1>0 && y2-y1>0){

y1++;

x2--;

bottomLeft(a,x1,y1,x2,y2);

}

}

void bottomLeft(int a[999][999], int x1, int y1, int x2, int y2) {

for (int i=x2;i>=x1;i--) a[y2][i]=d++;

for (int j=y2-1;j>=y1;j--) a[j][x1]=d++;

if (x2-x1>0 && y2-y1>0) {

x1++;

y2--;

topRight(a,x1,y1,x2,y2);

}

}

int main(void){

int a[999][999],m,n,i,j;

cout << "Insert n: ";

cin >> n;

cout << "Insert m: ";

cin >> m;

topRight(a,0,0,n-1,m-1);

cout << "

A spiral-shaped two-dimensional array whith size " << m << " x " << n << " is:

";

for(i=0;i

for(j=0;j

cout << a[i][j] << " ";

}

cout << "

";

}

}

我使用此命令在Ubuntu终端上编译:

g++ program.cpp -o program

并使用此命令运行它:

./program

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值