c++定义二维数组作业

[复制链接]
查看11 | 回复1 | 2010-5-4 22:33:04 | 显示全部楼层 |阅读模式
第一题#include using namespace std;int main(){ const int row = 5; const int col = 5; int val = 1; int a[row][col] = {0}; for (int i=0; i!=row; ++i) {
for (int j=0; jusing namespace std;int main(){ const int row = 6; const int col = 5; int val[row][col] = {{1001,90,80,85,0},
{1002,70,75,80,0},
{1003,65,70,75,0},
{1004,56,78,97,0},
{1005,80,90,70,0}}; for (int i=0; i<row-1; ++i) {
for (int j=1; j<col-1; ++j){
val[col-1] += val[j]; } } for (int j=1; j<col-1; ++j) {
for(int i=0; i<row-1; ++i){
val[row-1][j] += val[j];} } for (int i=0; i<row; i++) {
for(int j=0; j<col; j++){
cout << val[j] << "\t";}cout << endl; } system("pause");} 我是用VC++2008的,如果你是用其他的编译器,把system("pause");去掉,如果是用以前的标准的话把头文件改成iostream.h,把using namespace std;去掉应该可以了,不懂可以问我
回复

使用道具 举报

千问 | 2010-5-4 22:33:04 | 显示全部楼层
第一题:#includeusing namespace std;#define M 5void main(){ int A[M][M];int i,j;for(i=0; i<M; i++){ if(i==0)
for(j=0; j<M; j++) A[j]=j+1;
if(i==1)
for(j=1; j<M; j++) {A[0]=1; A[j]=j;}
if(i==2)
for(j=2; j<M; j++) {A[0]=A[1]=1; A[j]=j-1;}
if(i==3)
for(j=3; j<M; j++) {A[0]=A[1]=A[2]=1; A[j]=j-2;}
if(i==4)
for(j=4; j<M; j++) {A[0]=A[1]=A[2]=A[3]=1; A[j]=j-3;}
if(i==M)
for(j=0; j<M; j++) {A[j]=1;}}for(i=0; i<M; i++){ for(j=0; j<M; j++)
cout<<A[j]<<"";
cout<<endl; } }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行