欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

javafor循环打印图案_C程序使用循环打印盒子图案

发布时间:2025/3/11 编程问答 29 豆豆
生活随笔 收集整理的这篇文章主要介绍了 javafor循环打印图案_C程序使用循环打印盒子图案 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

javafor循环打印图案

Input a number and print the following box pattern in C language,

输入数字并以C语言打印以下框形 ,

4 4 4 4 4 4 44 3 3 3 3 3 4 4 3 2 2 2 3 4 4 3 2 1 2 3 4 4 3 2 2 2 3 4 4 3 3 3 3 3 4 4 4 4 4 4 4 4

Input format:

输入格式:

The input will contain a single integer.

输入将包含一个整数。

Constraints:

限制条件:

1<=n<=100

1 <= n <= 100

Output format:

输出格式:

Print the pattern mentioned in the problem statement.

打印问题陈述中提到的模式。

Example

Input:2Output:2 2 2 2 1 2 2 2 2

代码以C语言打印盒子图案 (Code to print the box pattern in C)

//Code to print the box pattern in C #include <stdio.h>int main() {int n, i, j, t; //n is representing number of the output box//input nprintf("Enter the value of n: ");scanf("%d", &n);t = 2 * n - 1;i = t; //i and j are the number of rows and columns of the box.j = t;// Declare box as a 2-D matrix having i number of rows //and j number of columnsint a[i][j], k, m, p;p = n;m = 0;for (k = 0; k < p; k++) {for (i = m; i < t; i++) {for (j = m; j < t; j++) {if (i == m || i == (t - 1) || j == m || j == (t - 1)) {a[i][j] = n;if (n == 1) {break;}}}}t = t - 1;n = n - 1;m = m + 1;}t = 2 * m - 1;for (i = 0; i < t; i++) {for (j = 0; j < t; j++) {printf("%d ", a[i][j]);}printf("\n");}return 0; }

Output

输出量

First run: Enter the value of n: 2 2 2 2 2 1 2 2 2 2Second run: Enter the value of n: 4 4 4 4 4 4 4 4 4 3 3 3 3 3 4 4 3 2 2 2 3 4 4 3 2 1 2 3 4 4 3 2 2 2 3 4 4 3 3 3 3 3 4 4 4 4 4 4 4 4

翻译自: https://www.includehelp.com/c-programs/print-box-pattern-using-loops.aspx

javafor循环打印图案

总结

以上是生活随笔为你收集整理的javafor循环打印图案_C程序使用循环打印盒子图案的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。