c++输出矩阵的和
0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7 8 9 10
0 2 4 6 8 10 12 14 16 18 20
0 3 6 9 12 15 18 21 24 27 30
0 4 8 12 16 20 24 28 32 36 40
0 5 10 15 20 25 30 35 40 45 50
0 6 12 18 24 30 36 42 48 54 60
0 7 14 21 28 35 42 49 56 63 70
0 8 16 24 32 40 48 56 64 72 80
0 9 18 27 36 45 54 63 72 81 90
0 10 20 30 40 50 60 70 80 90 100
4
--------------------------------
#include <iostream>
int a[11][11]={0};
int s[11][11]={0};
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int k=0;
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
a[i][j]=++k;
}
}
for(int i=0;i<=10;i++){
for(int j=0;j<=10;j++){
printf("%3d ",a[i][j]);
}
cout<<endl;
}
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
}
}
cout<<endl;
for(int i=0;i<=10;i++){
for(int j=0;j<=10;j++){
printf("%7d ",s[i][j]);
}
cout<<endl;
}
//输出右下角四个数的和
cout<<s[10][10]-s[10][8]-s[8][10]+s[8][8];
return 0;
}
更多推荐
所有评论(0)