关于数组的问题,小弟先谢过了!
raof 2006-08-07 09:09:52 (1)#include<iostream>
using namespace std;
int main()
{
int i,t,num[3][4];
for(t=0;t<3;++t)
{
for(i=0;i<4;++i)
{
num[t][i]=(t*4)+i+1;
cout<<num[t][i]<<' ';
}
cout<<endl;
}
return 0;
}
//输出结果:1 2 3 4
// 5 6 7 8
// 9 10 11 12
大哥们帮我解释一下这句:num[t][i]=(t*4)+i+1;
搞不太懂,刚学一个月的c++
(2)
#include<iostream>
using namespace std;
int sqrs[10][2]={
{1,1},
{2,4},
{3,9},
{4,16},
{5,25},
{6,36},
{7,49},
{8,64},
{9,81},
{10,100}
};
int main()
{
int i,j;
cout<<"Enter number between 1 and 10:";
cin>>i;
for(j=0;j<10;j++)
if(sqrs[j][0]==i) break;
cout<<"The square of "<< i <<" is ";
cout<<sqrs[j][1]<<endl;
return 0;
}
这个程序,为什么把break去掉,结果都为0???不懂,请指教!~