c语言之字方阵

来源:百度知道 编辑:UC知道 时间:2024/05/23 16:52:47
1 2 6 7 15↵
3 5 8 14 16↵
4 9 13 17 22↵
10 12 18 21 23↵
11 19 20 24 25↵

输入:
方阵N的大小。

输出
类似于上面的方阵。
科技鸟的回答好象不是C语言吧!

修改过了。
=========================
#include<stdio.h>
#include<cstdlib>
#include<time.h>
#include<vector>
using namespace std;
void main()
{
srand((unsigned int)time(NULL));
vector<int>a;
int n,count=0,temp;
printf("input the size of the phlanx(方阵大小)\n");
scanf("%d",&n);
for(int j=0;j<n*n;j++)
{

temp=rand()%100;
a.push_back(temp);
}
printf("\nthe phlanx is:\n");
int i=0;
while(1)
{
count++;
if((count)%5==0)
{
printf("%d 口\n",a[i]);
i++;
}
else
{
printf("%d ",a[i]);
i++;
}
if(count==n*n)
break;
}
}
============================