当前位置:网站首页>C语言:空心正方形图案
C语言:空心正方形图案
2022-07-29 02:17:00 【高邮吴少】
空心正方形图案:题目链接

#include<stdio.h>
int main()
{
int n=0;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
{
if(i==0||i==n-1)
{
for(int j=0;j<n;j++)
{
printf("* ");
}
printf("\n");
}
else
{
printf("*");
for(int j=0;j<2*n-3;j++)
{
printf(" ");
}
printf("*");
printf("\n");
}
}
}
}

该题需要注意的是,多组输入整形,那我们要用一个循环scanf来接收,scanf和getchar一样,没东西接收就返回一个-1(EOF)
然后就是除了第一行和最后一行,中间的空格是(n-1)+(n-2)=2n-3个
n-1是原本两*之间的空格数,n-2是原本 *的位置变成的空格。
边栏推荐
- FPGA skimming memory (Verilog implementation of ram and FIFO)
- K210——声源定位、声音识别
- MQTT例程
- Driverless obstacle avoidance technology
- STM32C8T6编码器电机测速与arduino光电模块测速
- C language to achieve the three chess game
- Flink内核源码(七)Flink SQL提交流程
- Asemi rectifier bridge s25vb100, s25vb100 parameters, s25vb100 application
- 深度剖析 —— 预处理
- Ten methods to prevent blackmail software from attacking data
猜你喜欢

3D intelligent factory process flow visualization interactive display application advantages

C语言:小乐乐与进制转换

JMeter's BeanShell generates MD5 encrypted data and writes it to the database

6 years of testing experience, teaching you how to test ~ how to control the project

Where, having, group by, order by, is null, not in, subquery, delete, date function

C language to achieve the three chess game

Youxuan software appoints Huang Zhijun as the general manager of the company

php 进程通信系列 (一) 命名管道

架构师进阶,微服务设计与治理的 16 条常用原则

第五天实验
随机推荐
以科技传递温度,vivo亮相数字中国建设峰会
STM32C8T6编码器电机测速与arduino光电模块测速
Polygon point test
第五天实验
第十天笔记
ROCBOSS开源微社区轻论坛类源码
Summary of knowledge points of Engineering Economics
Double write consistency of MySQL and redis
Multimodal unsupervised image to image translation
自组织是管理者和成员的双向奔赴
HTTP cache
idea替换所有文件中的内容
MQTT例程
Cuda-npp image and video processing
where、having、group by、order by,is null,not in,子查询,delete,日期函数
CUDA details GPU architecture
Source code and display of 18 classic programs in C language vs2019
Shell 脚本 快速入门 -01
[untitled]
3种过期策略