滴水逆向联盟
标题:
基于visual Studio2013解决C语言竞赛题之1058打印数字
[打印本页]
作者:
大灰狼
时间:
2014-8-14 08:44
标题:
基于visual Studio2013解决C语言竞赛题之1058打印数字
题目
download1.png
(4.27 KB, 下载次数: 255)
下载附件
保存到相册
2014-8-14 08:44 上传
解决代码及点评
[cpp]
view plain
copy
<pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">/************************************************************************/
/*
58. 编写程序,按照 1,2, ... , 28的顺序填一个7×7数组的左上角,程序的输出结果为:
1 2 4 7 11 16 22
3 5 8 12 17 23
6 9 13 18 24
10 14 19 25
15 20 26
21 27
28
*/
/************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
void main()
{
int arr[7][7]={0};
int num=(1+7)*7/2;
int m=0;
int n=0;
int cen=0;
for (int i=1;i<=num;i++)
{
arr[m][n]=i;
if (n-1<0)
{
m=0;
cen++;
n=cen;
}
else
{
m++;
n--;
}
}
for (int i=0;i<7;i++)
{
for (int j=0;j<7-i;j++)
{
printf("%5d",arr
[j]);
}
printf("\n");
}
system("pause");
}</pre><br><br></pre></pre></pre>
欢迎光临 滴水逆向联盟 (http://dtdebug.com/)
Powered by Discuz! X3.2