c打印一个N*N的方阵
打印一个N*N的方阵,N为每边字符的个数( 3〈N〈20 ),要求最外层为"X",第二层为"Y",从第三层起每层依次打印数字0,1,2,3,...
例子:当N =5,打印出下面的图形:
X X X X X
X Y Y Y X
X Y 0 Y X
X Y Y Y X
X X X X X
C/C++ code:
#include <iostream>
#include <iomanip>
using namespace std;
#define N 7 //这个大小可以改
char c[N][N];
int main()
{
for(int i=0; i<N; i++)
for(int j=0; j<N; j++)
{
int temp;
if(i<=j && i+j<=N-1)
temp = i;
else if(i>j && i+j>N-1)
temp = N-1 - i;
else if(i>j && i+j<=N-1)
temp = j;
else
temp = N-1 - j;
if(temp == 0)
c[i][j] = 'X';
else if(temp == 1)
c[i][j] = 'Y';
else
c[i][j] = '0' + temp - 2;
}
for( i=0; i<N; i++)
{
for( int j=0; j<N; j++)
{
printf("%5c",c[i][j]);
}
printf("\n");
}
}
看看
首先谢谢1楼!
有没有不分配存储空间的方法?
#include <stdio.h>
#include <stdlib.h>
相关问答:
有这样两个问题,希望高手指点:
第一:
struct struct_A{
int a;
char b;
int c;
short d;
}
struct struct_B{
int a;
char b;
short c;
......
我现在想将这四个文件从服务器\\10.2.95.88\temp目录下的四个文本文件:1.txt ,2.txt ,3.txt , 4.txt从服务器下载到本地机的C:\temp目录下?
上述的功能我想用纯C应该如何实现?
用ftp协议就可以了
引用 ......
c/s 和b/s 的区别是什么,c/s需要服务器吗,怎么判断程序是c/s 还是b/s
C/S是服务器和客户端 B/S是服务器和浏览器
他们都有s,什么是s?就是server
那他们的区别是什么?一个是c,即client,一个 ......
/*-----------c.h--------------*/
#ifndef _C_H_
#define _C_H_
extern "C" int add(int x, int y);
#endif
/*-----------c.c--------------*/
int add(int x, int y){
return ......