当前位置:网站首页>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 .
边栏推荐
猜你喜欢

OSPF实验

New UI Sifang aggregate payment system source code / new usdt withdrawal / latest update security upgrade to fix XSS vulnerability patch vulnerability

DHCP协议详细解析

MPEG音频编码三十年

golang 协程的实现原理

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

Rocbos open source micro community light forum source code

多重继承与派生类成员标识

以科技传递温度,vivo亮相数字中国建设峰会

etcd实现大规模服务治理应用实战
随机推荐
Library management system
NVIDIA-VPI(Vision Programming Interface)
php 进程通信系列 (一) 命名管道
Read the recent trends of okaleido tiger and tap the value and potential behind it
DataGrip 如何导出和恢复整个数据库数据,使用单个 SQL 文件
第八天笔记
以科技传递温度,vivo亮相数字中国建设峰会
Shell script quick start-01
This blogger has a comprehensive classification of QT. If you are free, go to study and summarize it and record it.
漫画算法_小灰灰面试
Redis master-slave mode, sentinel cluster, fragment cluster
架构师进阶,微服务设计与治理的 16 条常用原则
CUDA details GPU architecture
区区区间---线段树lazy标记板子题
C语言:小乐乐与欧几里得
Only when you are far away will you miss
九宫格心形拼图小程序源码/带流量主微信小程序源码
Driverless obstacle avoidance technology
ASEMI整流桥S25VB100,S25VB100参数,S25VB100应用
远离才会思念