当前位置:网站首页>C language: hollow square pattern
C language: hollow square pattern
2022-07-29 02:47:00 【Gao You Wu Shao】
Hollow square pattern : Topic link
#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");
}
}
}
}
What we need to pay attention to is , Multiple input shaping , Then we need to use a cycle scanf To receive ,scanf and getchar equally , If there is nothing to receive, return one -1(EOF)
Then there is the first line and the last line , The space in the middle is (n-1)+(n-2)=2n-3 individual
n-1 It's the original two * The number of spaces between ,n-2 It's the original * The position of becomes a space .
边栏推荐
猜你喜欢
随机推荐
time_ Wait and close_ Cause of wait
Source code and display of 18 classic programs in C language vs2019
Where, having, group by, order by, is null, not in, subquery, delete, date function
QT屏幕自适应自动布局,拖动窗口自动变大变小(一)
第六天笔记
idea替换所有文件中的内容
0728~ sorting out interview questions
(作业)C语言:atoi和strncpy、strncat、strncmp的模拟实现
Driverless obstacle avoidance technology
What are the TCP retransmission mechanisms?
第七天笔记
平凡的快乐
K210——声源定位、声音识别
Understanding service governance in distributed development
A good-looking IAPP donation list source code
第八天笔记
STM32C8T6编码器电机测速与arduino光电模块测速
Which is a good automatic account distribution system?
多年前的回忆
Code implementation - the greatest common factor of polynomials (linear algebra)