javafor循环打印图案_C程序使用循环打印盒子图案
生活随笔
收集整理的這篇文章主要介紹了
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 4Input 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程序使用循环打印盒子图案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: BBIAF的完整形式是什么?
- 下一篇: 大年初一,磊哥给大家发大红包啦!