|  | 
 
| 
输出二维数组
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  1 2 3 4 5 6
 1 1 2 3 4 5
 1 2 1 2 3 4
 1 3 3 1 2 3
 1 4 6 4 1 2
 1 5 10 10 5 1
 题目:
 #include <iostream>
 #include <iomanip>
 using namespace std;
 int main()
 { int a[6][6],i,j;
 for(i=0;i<6;i++)
 {
 for(j=0;j<6;j++)
 {
 if(要填的地方)a[i][j]=1;
 else if(i<j)要填的地方
 else a[i][j]=要填的地方
 
 cout<<setw(6)<<a[i][j];
 }
 cout<<'\n';
 }
 }
 
 
 我的代码:
 #include <iostream>
 #include <iomanip>
 using namespace std;
 int main()
 { int a[6][6],i,j;
 for(i=0;i<6;i++)
 {
 for(j=0;j<6;j++)
 {
 if((j=0) ||(i=j))a[i][j]=1;
 else if(i<j)a[i][j]=j-i+1;
 else a[i][j]=i*(i-j);
 
 cout<<setw(6)<<a[i][j];
 }
 cout<<'\n';
 }
 }
 我感觉逻辑没错却一直打印0搞不懂了
 
 本帖最后由 傻眼貓咪 于 2022-3-26 11:41 编辑 
复制代码#include <iostream>
#include <iomanip>
using namespace std;
int main(){
        int a[6][6], i, j;
        for(i = 0; i < 6; i++){
                for(j = 0; j < 6; j++){
                        if(!j || (i == j)) a[i][j] = 1;
                        else if(i < j) a[i][j] = j + 1 - i;
                        else a[i][j] = a[i-1][j-1] + a[i -1][j];
                        cout << setw(6) << a[i][j];
                }
                cout << '\n';
        }
}
 | 
 |