当前位置:网站首页>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;
}
边栏推荐
- 移动端常用解决方案
- OpenGL ES: (3) EGL、EGL绘图的基本步骤、EGLSurface、ANativeWindow
- 【知识点总结】卡方分布,t分布,F分布
- First defined here occurs during QT compilation. Causes and Solutions
- vsCode函数注解/文件头部注解快捷键
- Chapitre d'apprentissage mongodb: Introduction à la première leçon après l'installation
- Learn the customization and testing of fpga---ram IP from the bottom structure
- 2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)
- OneFlow源码解析:算子签名的自动推断
- Advanced cross platform application development (II): uni app practice
猜你喜欢
Leetcode Max rectangle, Max square series 84 85. 221. 1277. 1725. (monotonic stack, dynamic programming)
This is the necessary software for college students 𞓜 knowledge management
College community management system based on boot+jsp (with source code download link)
Advanced cross platform application development (III): online resource upgrade / hot update with uni app
Ssm+mysql second-hand trading website (thesis + source code access link)
Educational administration management system of SSM (free source code)
Qt编写自定义控件-自绘电池
C语言初阶——牛客网精选好题
为了保护自己的数据,他奋斗了一天一夜
小程序常用组件小结
随机推荐
Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation
rust猜数字游戏
OpenGL ES: (3) EGL、EGL绘图的基本步骤、EGLSurface、ANativeWindow
【考研高数 自用】高数第一章基础阶段思维导图
4GB大文件,如何实时远程传输和共享?
Data governance: data governance management (Part V)
Common solutions for mobile terminals
HDU - 1069 Monkey and Banana(DP+LIS)
导数的左右极限和左右导数的辨析
This is the necessary software for college students 𞓜 knowledge management
新手在挖财开通证券账户安全吗?
【QT】qt加减乘除之后,保留小数点后两位
JSON data comparer
健康照明中应用的LED照明灯
[medical segmentation] u2net
芯片,建立在沙粒上的帝国!
Qt编写自定义控件-自绘电池
MySQL数据迁移遇到的一些错误
In depth understanding of condition source code interpretation and analysis of concurrent programming
为什么用葫芦儿派盘取代U盘?