日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2025/3/11 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 javafor循环打印图案_C程序使用循环打印盒子图案 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

javafor循環(huán)打印圖案

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

輸入數(shù)字并以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.

輸入將包含一個整數(shù)。

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循環(huán)打印圖案

總結(jié)

以上是生活随笔為你收集整理的javafor循环打印图案_C程序使用循环打印盒子图案的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。