注册 登录
编程论坛 C++教室

[求助]程序没一点问题,怎么就是不出结果,我老师也看不出来!

liujun850215 发布于 2007-04-09 18:30, 523 次点击
#include <iostream.h>
#define ROW 3
#define COL 4
void main()
{int b[ROW][COL],i,j,r1=0,r2=0,r3=0;
for(i=0;i<=ROW;i++)
for(j=0;j<=COL;j++)
{b[i][j]=3*i+2*j-6;
while(i==1)
{r1+=b[i][j];}
while(j==4)
{r2+=b[i][j];}
while(i==j)
{if(b[i][j]<0) r3++;}}
cout<<r1<<endl;
cout<<r2/4<<endl;
cout<<r3;}
7 回复
#2
aipb20072007-04-09 22:18
#include <iostream.h>
#define ROW 3// 改成const int ROW = 3;
#define COL 4
// 改成const int COL = 4;
void main()
{int b[ROW][COL],i,j,r1=0,r2=0,r3=0;
for(i=0;i<=ROW;i++)
for(j=0;j<=COL;j++)
{b[i][j]=3*i+2*j-6;
while(i==1)
{r1+=b[i][j];}
while(j==4)
{r2+=b[i][j];}
while(i==j)
{if(b[i][j]<0) r3++;}}
cout<<r1<<endl;
cout<<r2/4<<endl;
cout<<r3;}
#3
liujun8502152007-04-09 23:44

还是不行啊,就是不弄全局变量还是不行呀!

#4
wfpb2007-04-09 23:53

你们老师也真够笨的.
数组越界不知道?
两个循环中的<=换成<

#5
幽灵嫖客2007-04-10 07:11
好像你的while循环不能退出压!
#6
yuyunliuhen2007-04-10 10:12
4楼对的,

[此贴子已经被作者于2007-4-10 10:19:57编辑过]

#7
czcoder2007-04-10 11:21
数组的确越界了
#8
liujun8502152007-04-10 12:36

谢谢了!

1