当前位置:网站首页>Preliminary level of C language -- selected good questions on niuke.com
Preliminary level of C language -- selected good questions on niuke.com
2022-07-01 05:46:00 【Xiao LV LC】
List of articles
BC68 X 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 X Shape patterns .
Input description :
Multi group input , An integer (2~20), Represents the number of rows output , It also means composition “X” The length of the backslash and the backslash of .
Output description :
Enter... For each line , For output “*” Composed of X Shape patterns .
#define _CRT_SECURE_NO_WARNINGS 1 // Make sure scanf Functions can all be vs Use... Under compiler
#include <stdio.h>
int main()
{
char arr[20][20] = {
0 }; // Create a 2D array
int i = 0;
int j = 0;
int a = 0;
while (scanf("%d", &a)!=EOF) // Use loops to implement multiple sets of inputs
{
for (i = 0;i < 20;i++) // Initialize all array elements to spaces
{
for (j = 0;j < 20;j++)
{
arr[i][j] = ' ';
}
}
for (i = 0, j = 0;i < a, j < a;i++, j++) // The positive diagonal element is changed to ‘*’
{
arr[i][j] = '*';
}
for (i = 0, j = a - 1;i < a, j >= 0;i++, j--) // The anti diagonal element is changed to ‘*’
{
arr[i][j] = '*';
}
for (i = 0;i < a;i++) // Print out elements
{
for (j = 0;j < a;j++)
{
printf("%c", arr[i][j]);
}
printf("\n");
}
}
return 0;
}

BC54 Get the number of days in the month
describe
KiKi Want to get how many days there are in a certain month in a certain year , Please program it for him . Enter the year and month , Calculate the number of days in this month of the year .
Input description :
Multi group input , There are two integers in a row , Represents year and month respectively , Separate... With spaces .
Output description :
Enter... For each group , Output as a line , An integer , It means how many days there are in this month of the year .
#define _CRT_SECURE_NO_WARNINGS 1 // Make sure scanf Functions can all be vs Use... Under compiler
#include <stdio.h>
int is_leap_yeay(int x) // Determine whether the year is a leap year
{
if (((x % 4 == 0) && (x % 100 != 0)) || x % 400 == 0)
return 29;
else
return 28;
}
int main()
{
int year = 0;
int month = 0;
int a = 0;
while (scanf("%d%d", &year, &month)!=EOF)
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) // Big moon is 31 God
{
printf("31\n");
}
else if (month == 2) //2 Month is a special month , Call the function to determine whether it is a leap year
{
int a = is_leap_yeay(year);
printf("%d\n", a);
}
else // Other cases are Xiaoyue 30 God
{
printf("30\n");
}
}
return 0;
}
BC51 Triangle judgment
describe
KiKi Want to know the three sides that have been given a,b,c Can it form a triangle , If you can form a triangle , Judge the type of triangle ( Equilateral triangle 、 Isosceles triangle or ordinary triangle ).
Input description :
The title has multiple sets of input data , Enter three... On each line a,b,c(0<a,b,c<1000), As the three sides of a triangle , Separate... With spaces .
Output description :
Enter data for each group , Output takes up one line , If you can form a triangle , Equilateral triangles output “Equilateral triangle!”, Isosceles triangle outputs “Isosceles triangle!”, The rest of the triangles are output “Ordinary triangle!”, On the contrary, output “Not a triangle!”.
#define _CRT_SECURE_NO_WARNINGS 1 // Make sure scanf Functions can all be vs Use... Under compiler
#include <stdio.h>
int main()
{
int a = 0;
int b = 0;
int c = 0;
while (scanf("%d%d%d", &a, &b, &c)!=EOF)
{
if ((a + b > c) && (a + c > b) && (b + c > a)) // Judge whether it is a triangle
{
if ((a == b && b!=c )|| (b == c && c!=a)|| a == c && c!=b) // Judge whether it is an isosceles triangle
{
printf("Isosceles triangle!\n");
}
else if (a == b && b == c && c == a) // Judge whether it is an equilateral triangle
{
printf("Equilateral triangle!\n");
}
else
{
printf("Ordinary triangle!\n");
}
}
else
{
printf("Not a triangle!");
}
}
return 0;
}
边栏推荐
- First defined here occurs during QT compilation. Causes and Solutions
- 2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)
- Unity 使用Sqlite
- Boot + jsp University Community Management System (with source Download Link)
- Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation
- Dear pie users, I want to confess to you!
- Unity uses SQLite
- 多表操作-外键级联操作
- [ffmpeg] [reprint] image mosaic: picture in picture with wheat
- 穿越派·派盘 + Mountain Duck = 数据本地管理
猜你喜欢

4GB大文件,如何实时远程传输和共享?

穿越派·派盘 + Mountain Duck = 数据本地管理

【知识点总结】卡方分布,t分布,F分布

基于TI DRV8424驱动步进电机实现调速和行程控制

2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)

Educational administration management system (free source code)

穿越派·派盘 + 思源笔记 = 私人笔记本

芯片,建立在沙粒上的帝国!

Why use huluer pie disk instead of U disk?

HCM 初学 ( 四 ) - 时间
随机推荐
Geoffrey Hinton:我的五十年深度学习生涯与研究心法
vsCode函数注解/文件头部注解快捷键
Typeorm framework
Dear pie users, I want to confess to you!
Mongodb学习篇:安装后的入门第一课
亲爱的派盘用户,我要向您表白!
π盘,让您电脑变成个人的私有云
HCM 初学 ( 三 ) - 快速输入PA70、PA71 浏览员工信息PA10
On the first day of the new year, 3000 Apache servers went down
What is the at instruction set often used in the development of IOT devices?
从底层结构开始学习FPGA----RAM IP的定制与测试
新手在挖财开通证券账户安全吗?
导数的左右极限和左右导数的辨析
基于微信小程序的青少年生理健康知识小助手(免费获取源码+项目介绍+运行介绍+运行截图+论文)
HDU - 1069 Monkey and Banana(DP+LIS)
为了保护自己的数据,他奋斗了一天一夜
数据治理:数据治理框架(第一篇)
Printk debugging summary
Unity 使用Sqlite
Basic electrician knowledge 100 questions