大一作业题求解,打印方阵问题
问题描述:
答
// Q947968.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
int main(int argc, char* argv[])
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (i == 0 || i == n - 1 || j == 0 || j == n - 1) printf("O");
else if (i == 1 || i == n - 2 || j == 1 || j == n - 2) printf("J");
else printf("%d", i - 1);
}
printf("\n");
}
return 0;
}