发新话题
打印

C/C++面试题解

面霸应届生求职网欢迎您!

C/C++面试题解

C/C++面试题解  
题目内容
C/C++面试题解- -
Tag: C/C++面试题解

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);
}
2.如何打印出当前源文件的文件名以及源文件的当前行号?

cout <<"FILE:"<<__FILE__< <<"Line:"<<__LINE__< <<"Time:"<<__TIME__< <<"Date:"<<__DATE__< 3.如何判断一段程序是由C编译程序还是由C++编译程序编译的?

c++编译定义了: __cplusplus
c编译定义了: __STDC__
支持 辛苦了!!
面霸网
发新话题