C/C++面试题解
来源:互联网 发布:悟空网络加速器官网 编辑:程序博客网 时间:2024/04/26 05:31
1.输入一个n ,然后在屏幕上打印出NxN 的矩阵!
例如,输入一个3,则
1 2 3
8 9 4
7 6 5
输入一个4,则
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
解:
#include
#include
using namespace std;
const int N=10;
void print(int a[][N],int n)
{
int round=0;
int i,j;
int m=1;
while(m<=n*n)
{
for(i=round;i a[round]=m++;
for(i=round+1;i a[n-round-1]=m++;
for(i=n-round-2;i>=round;i--)
a[n-round-1]=m++;
for(i=n-round-2;i>=round+1;i--)
a[round]=m++;
round++;
}
for(i=0;i {
for(j=0;j {
cout < }
cout << endl;
}
}
void main()
{
int a[N][N];
int round=0;
int n,m=1;
cout << "Please input n:";
cin>>n;
print(a,n);
}
例如,输入一个3,则
1 2 3
8 9 4
7 6 5
输入一个4,则
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
解:
#include
#include
using namespace std;
const int N=10;
void print(int a[][N],int n)
{
int round=0;
int i,j;
int m=1;
while(m<=n*n)
{
for(i=round;i a[round]=m++;
for(i=round+1;i a[n-round-1]=m++;
for(i=n-round-2;i>=round;i--)
a[n-round-1]=m++;
for(i=n-round-2;i>=round+1;i--)
a[round]=m++;
round++;
}
for(i=0;i {
for(j=0;j {
cout < }
cout << endl;
}
}
void main()
{
int a[N][N];
int round=0;
int n,m=1;
cout << "Please input n:";
cin>>n;
print(a,n);
}
- C/C++面试题解
- 最全的C/C++面试题解
- 最全的C/C++面试题解(1)
- 最全的C/C++面试题解(2)
- 面试题解:二维数组中的查找(C 语言版)
- C面试
- C++ 面试
- c面试
- C面试
- C++/C 面试
- c++/c面试宝典
- 校赛C题题解
- C谜题解释
- C/C++相关题解
- C谜题解释
- codeforces 585C题解
- BZOJ 1042题解(C++)
- C语言考试题解
- Lamp系统调优3
- c++书籍的层次与境界
- 2007.11.20第一次写这里的博客
- linux ES4下oracle10g安装心得
- 求助,我想学习ASP
- C/C++面试题解
- 膳食中的十大平衡
- CString-clone Using Standard C++
- 探讨修复光盘的可能http://www.moon-soft.com/book/ttxfgpdkn.htm
- SQL SERVER 2005数据库镜像(上)
- 自动光盘修复机,拯救损坏的光盘http://hard.zol.com.cn/2004/0614/102449.shtml
- 如何修复有划痕的光盘http://www.hongen.com/pc/diy/problem/hard/cdrom/index2.htm
- SQL SERVER 2005数据库镜像(中)
- C# 进度条窗口 有取消按按钮