table.cpp

来自「学生类代码有此推广到时间年月日的编写」· C++ 代码 · 共 28 行

CPP
28
字号
#include<iomanip.h>
#include<iostream.h>
void colsum(int a[][4],int nrow)
{
	for(int j=0;j<4;j++)
	{
		for(int i=1;i<nrow;i++)
			a[0][j]+=a[i][j];
	}
}
void main()
{
	int a[3][4];
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<4;j++)
		{
			a[i][j]=i*4+j+5;
			cout<<setw(4)<<a[i][j];
		}
		cout<<endl;
	}
	colsum(a,3);
	for(i=0;i<4;i++)
		cout<<"sum of col "<<i<<" is "<<a[0][i]<<endl;
	cout<<endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?