javafor循环打印图案

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

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

    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

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:
2
Output:
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 n
printf("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 columns
int 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 2
Second 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程序使用循环打印盒子图案相关推荐

  1. c语言 for循环说课,《程序的循环结构-For循环语句》教学设计

    一.教学对象 本教案适用于新课程标准下高中一年级学生,教材选用广东版信息技术选修模块一<算法与程序设计>2.4.1节,1课时.在学习本课之前,学生应掌握VB程序的编程环境与运行方法,了解顺 ...

  2. while循环random结合_Python程序控制结构 | 循环结构

    本节内容框架 遍历循环 定义:遍历某个结构形成的循环方式 用法: for 循环变量 in 遍历结构: 语句块 理解: - 从遍历结构中逐一提取元素,放在循环变量中 - 由保留字for和in组成,完整遍 ...

  3. 标签云打印/微信小程序蓝牙标签打印开放平台功能

    ​微信小程序蓝牙标签打印/标签云打印开放平台(www.herro.cn),是在云端部署的云平台,支持开发者通过API调用完成标签蓝牙打印或标签云打印功能. 平台蓝牙打印模块支持各厂商各品牌蓝牙标签打印 ...

  4. c语言for循环++_C ++程序使用循环查找数字的幂

    c语言for循环++ Here, we are going to calculate the value of Nth power of a number without using pow func ...

  5. c 指针打印变量_C程序打印不同类型的指针变量的大小。

    c 指针打印变量 Any type of pointer variable takes the same memory bytes in the memory, because they are us ...

  6. python循环结构代码_Python --- 程序的循环结构

    遍历某个结构形成的循环运行方式,从遍历结构中逐一提取元素,放在循环变量中 for in : 由保留字for和in组成,完整遍历所有元素后结束 每次循环,所获得元素放入循环变量,并执行一次语句块 遍历循 ...

  7. c语言打印图案的程序,C语言打印心图案----真好玩

    普通的爱心图案 #include #include int main() { float y, x, a; for (y = 1.5f;y > -1.5f;y -= 0.1f) { for (x ...

  8. c语言打印日历的程序,简单日历打印(C语言)

    #include #include #include "tuisuan.h" int y,year=1; int main() { char name ; printf (&quo ...

  9. 计算机 打印 速度慢,处理打印机在打印文件时打印速度过慢的原因

    打印机是上班人员经常要用到的工具,那么打印机在打印文件时速度很慢是怎么回事呢?是什么造成的呢?如果现在你还不知道,那你就应该了解一下啦,接下来给大家讲讲打印机打印速度慢的原因,一起去看看吧. 操作方法 ...

最新文章

  1. 2018/8/28-29 Some metaheuristics should be simplified
  2. 神经网络注意力机制--Attention in Neural Networks
  3. 5.6 前端开发日报
  4. 02_MySQL约束课堂笔记
  5. el-select 多选取值_数值优化|笔记整理(3)——线搜索中的步长选取方法,线性共轭梯度法...
  6. 翻译:重载解决和Null
  7. 数据库语句数据库学习(3)——数据库的创建与删除
  8. 厉害!一年两登顶刊的31岁浙大硕导荣获杰青!
  9. 常见路由器默认用户名和密码
  10. chisel线网(wire)和寄存器(reg)详解(更新)
  11. 应用交付学习笔记三-BIG-IP LTM健康检查
  12. PHP程序员必看书籍
  13. android Acitvity action,flag和category各个参数的说明 .
  14. tensorboard 2.0可视化 —浏览器中输入http://ip:6006 - 无法访问此网站——有效解决
  15. 查询京东快递物流状态,快速筛选出代收的单号
  16. 卖场型旗舰店好入驻吗?需要什么资料?
  17. NLP自然语言处理之情感分析分析讲解、知识构建
  18. 技术赋能数字经济释放巨大潜力
  19. 吴恩达机器学习 EX7 第二部分 主成分分析(PCA)
  20. AutoCAD中程序化加载.NET程序集的方法

热门文章

  1. assertpythonraise_使用assertRaise测试异常消息
  2. oracle无法分区,oracle已存在的表添加新分区的方法
  3. 怎么利用迭代器写入mysql_range()是什么?为什么不生产迭代器?
  4. python字符串百分号_Python字符串格式化的2种方法
  5. 安装python3.9
  6. JDK源码解析之Java.util.Collections
  7. 使用ogg实现oracle到kafka的增量数据实时同步
  8. UVA1584 ​​​​​​​Circular Sequence【字符串】
  9. Oracle关联查询-数据类型不一致问题 ORA-01722: 无效数字
  10. 前端页面:一直报Cannot set property 'height' of undefined