C_使用二维数组作出矩阵图
源码:
# include <stdio.h>
int main()
{
int array[16][16];
int i, j, k, m, n;
/* 变量初始化 */
m = 1;
while(m == 1)
{
printf("请输入n(0<n<=15且为奇数):");
scanf("%d", &n);
/* 判断n是否是大于0小于等于15的奇数 */
if((n!=0) && (n<=15) && (n%2!=0))
{
printf("矩阵阶数是 %d\n", n);
m = 0; // 制造循环输入机制,直到输入正确方可退出循环
}
}
/* 数组赋初值为0 */
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
array[i][j] = 0;
/* 建立魔方阵 */
j = n/2 + 1;
array[1][j] = 1; // 将首行正中间元素设置为1
/* 此时i与j都等于n */
for(k=2; k<=n*n; k++)
{
i = i - 1; // 回到上一行
j = j + 1; // 去往下一列
if((i<1) && (j>n)) // 若是行到达首行且列到达尾列,前进两行,退一列
{
i = i + 2;
j = j - 1;
}
&nb
相关文档:
源码:
# include <stdio.h>
int main()
{
/* 换行符'\n',用于输出换行 */
printf("How are you?\n");
printf("I am fine.\n\n");
/* 横向跳格符'\t',使跳到下一个输出区 */
  ......
源码:
# include <stdio.h>
int main()
{
/* 定义字符型变量,并给它们付初值 */
char c1, c2, c3, c4, c5, c6, c7;
c1 = 'C';
c2 = 'h';
c3 = 'i';
c4 = 'n';
& ......
源码:
# include <stdio.h>
int main()
{
int x, y, z, mid, dec;
printf("请任意输入三个整数:\n");
scanf("%d %d %d", &x, & ......
源码:
# include <stdio.h>
int main()
{
int x, y;
printf("请输入自变量x:");
scanf("%d", &x);
if(x < 6)
{
  ......
源码:
# include <stdio.h>
int main()
{
int x, y, num1, num2, temp;
printf("请输入两个正整数:\n");
scanf("%d %d", &num1, &num2);
if(num1 < num2)
......