当前位置:网站首页>Niuke net question brushing training (II)
Niuke net question brushing training (II)
2022-07-21 05:32:00 【Wind rises and falls】
Blog home page : Wind up Wind fall The blog home page of
Welcome to pay attention to the likes and comments
Reference website : Cattle from
Starting time :2022 year 7 month 19 Japan
Your income is directly proportional to your irreplaceable
If you think the blogger's article is good , Please support the blogger for the third company
I'd like to introduce you to a job search question brushing harvest offer The place of Click to enter the website
List of articles
1.k Shape patterns
describe
KiKi I learned the cycle ,BoBo The teacher gave him a series of printing exercises , The task is to print “*” Composed of K Shape patterns .
Input description :
Multi group input , An integer (2~20).
Output description :
Enter... For each line , For output “” Composed of K shape , Every “” There is a space after .
#include<stdio.h>
int main()
{
int n=0;
scanf("%d",&n);
int i=0;
int j=0;
for(i=0;i<n;i++)// by n Lower triangle of
{
for(j=0;j<n+1-i;j++)
{
printf("* ");
}
printf("\n");
}
for(i=0;i<n+1;i++)// by n+1 The upper triangle of
{
for(j=0;j<=i;j++)
{
printf("* ");
}
printf("\n");
}
return 0;
}
This question Main thought It is divided into n Lower triangle of and n+1 The upper triangle of
Realize The number of characters
2. Arrow pattern
describe
KiKi I learned the cycle ,BoBo The teacher gave him a series of printing exercises , The task is to print “” Arrow shaped pattern composed of .
Input description :
Multiple groups of input , One integer per row (2~20).
Output description :
Enter... For each line , For output “” The shape of an arrow .
#include<stdio.h>
int main()
{
int n=0;
int i=0;
int j=0;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)//g by n The upper triangle of
{
for(j=0;j<n-i;j++)// Print space
{
printf(" ");
}
for(j=0;j<=i;j++)// Number of characters per line
{
printf("*");
}
printf("\n");
}
for(i=0;i<n+1;i++)// by n+1 Lower triangle of
{
for(j=0;j<2*i;j++)// Print space
{
printf(" ");
}
for(j=0;j<n+1-i;j++)// Number of characters per line
{
printf("*");
}
printf("\n");
}
}
return 0;
}
It is mainly divided into n The upper triangle of and n+1 Lower triangle of
Here we need to pay special attention to the existence of spaces , Every time 2 A space
Both look very outrageous , In fact, they are all formed by the normal upper and lower triangles
The title also requires multiple groups of input If not while Will not pass
3. Backslash pattern
describe
KiKi I learned the cycle ,BoBo The teacher gave him a series of printing exercises , The task is to print “” It's a reverse diagonal pattern .
Input description :
Multi group input , An integer (2~20), Represents the number of rows output , It also means to make up the backslash “” The number of .
Output description :
Enter... For each line , For output “*” The backslash of the composition .
#include<stdio.h>
int main()
{
int i=0;
int j=0;
int n=0;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)// Behavior n As a n The square of
{
for(j=0;j<n;j++)
{
if(i==j)
{
printf("* ");
}
else
printf(" ");
}
printf("\n");
}
}
return 0;
}
We just need to think of this as a square Each is marked with a subscript If i The coordinates and j The coordinates of are equal Is the pattern in the figure
Here's the thing to notice ; Be sure to add the return that cannot meet the condition Space , Otherwise it won't pass
4. Slash pattern
describe
KiKi I learned the cycle ,BoBo The teacher gave him a series of printing exercises , The task is to print “” It's a straight diagonal pattern .
Input description :
Multi group input , An integer (2~20), Represents the number of rows output , It also means that it is composed of “” The number of .
Output description :
Enter... For each line , For output “*” The forward and diagonal lines formed .
#include<stdio.h>
int main()
{
int i=0;
int j=0;
int n=0;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i+j==n-1)
{
printf("* ");
}
else
{
printf(" ");
}
}
printf("\n");
}
}
return 0;
}
``
We just need to think of this as a square Each is marked with a subscript If i Coordinates of plus j The coordinates of are row or column +1
Is the pattern in the figure
Here's the thing to notice ; Be sure to add the return that cannot meet the condition Space , Otherwise it won't pass
5. Hollow square pattern
describe
KiKi I learned the cycle ,BoBo The teacher gave him a series of printing exercises , The task is to print “” Composed of “ Hollow ” Square pattern .
Input description :
Multi group input , An integer (3~20), Represents the number of rows output , It also means that the sides of a square are made up of “” The number of .
Output description :
Enter... For each line , For output “” Composed of “ Hollow ” Square , Every “” There is a space after .
#include <stdio.h>
int main()
{
int n = 0;
while(scanf("%d", &n) != EOF)
{
for(int i=0; i<n; i++) // The outer loop is a line
{
for(int j=0; j<n; j++) // The inner loop is listed as
{
if(i==0||i==n-1||j==0||j==n-1)// Looking for a regular
printf("* ");
else
printf(" ");
}
printf("\n");
}
}
}
We just need to think of this as a square Each is marked with a subscript
When the first line , Enter characters on the last line
When it is the first column , Enter characters in the last column
The most important thing to pay attention to here is : The space is two spaces Don't ask me. How do you know
Almost spit blood
summary
From Cattle from The exercises of
I believe it will be beneficial to learning c Language is more interesting , Let's go
Less confident friends can take a look at this training
边栏推荐
猜你喜欢
Location unavailable - file or directory is corrupt and unreadable
CTFShow-MISC入门篇
Object.defineProperty使用
JUC包下的常见类
Use r to delete rows with empty cells from Excel
Flume的学习笔记
微信、QQ、电话下单,在线订货系统助企业走出困局
Iptables防火墙实验
[hbuilder runs to the problem that Mumu simulator cannot install the base, and it has been stuck in the installation base...]
经典网络学习-ResNet代码实现
随机推荐
Routing of upper layer loops in VRRP
Scala变量和数据类型(01)
ASP. Net core using Autofac
[Verilog digital system design (Xia Yuwen) -- basic knowledge of Verilog 2]
微服务入门
牛客网刷题训练(二)
Using hashes to solve problems
R语言快速绘制多因素回归分析森林图
uniapp使用uni.request请求报错{“errMsg“:“request:fail abort statusCode:-1“}的解决办法
JUC进阶-NO.1 线程基础知识复习
Drawing multi group Y-axis truncation graph with R language
Add a new field at the specified position in the MySQL table
Iptables防火墙实验
R 语言数据分析与统计软件应用 第一单元练习 (要求提交代码和结果文件)
Spark高效数据分析04、RRD创建
VS2017修改默认包含目录、库目录
R语言中插补缺失值的R包simputation
Nuscenes数据集总结
逆向分析工具IDA与开源工具Ghidra、Cutter对比测评
6.0 保存银联参数出错:Unable to open file