当前位置:网站首页>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;
}
边栏推荐
- Summary of common components of applet
- [excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
- Mongodb learning chapter: introduction after installation lesson 1
- Unity 使用Sqlite
- Looking for high school student developers with similar interests
- 我从技术到产品经理的几点体会
- Geoffrey Hinton:我的五十年深度学习生涯与研究心法
- 教务管理系统(免费源码获取)
- 穿越派与贸大合作,为大学生增添效率
- Qt编译时,出现 first defined here,原因及解决方法
猜你喜欢

CJC8988带2个立体声耳机驱动器的低功率立体声编解码器
![[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc](/img/c8/e3e31ad9ef214d97228cb501dd752f.jpg)
[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc

MySQL converts milliseconds to time string

This is the necessary software for college students 𞓜 knowledge management
![Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation](/img/83/97c0c6e23cbb7b4c2b630c217c5206.jpg)
Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation

Build 2022 上开发者最应关注的七大方向主要技术更新

boot+jsp的高校社團管理系統(附源碼下載鏈接)

Advanced cross platform application development (III): online resource upgrade / hot update with uni app

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

亲爱的派盘用户,我要向您表白!
随机推荐
数据治理:数据治理框架(第一篇)
2022.6.30-----leetcode. one thousand one hundred and seventy-five
tese_ Time_ 2h
Unity uses SQLite
穿越派·派盘 + Mountain Duck = 数据本地管理
POL8901 LVDS转MIPI DSI 支持旋转图像处理芯片
穿越派 你的数据云行
基于TI DRV8424驱动步进电机实现调速和行程控制
LeetCode 最大矩形,最大正方形系列 84. 85. 221. 1277. 1725. (单调栈,动态规划)
OpenGL ES: (2) OpenGL ES 与 EGL、GLSL的关系
2022第八届中国国际“互联网+”大学生创新创业大赛产业命题赛道开启报名!
穿越派·派盘 + 思源笔记 = 私人笔记本
HDU - 1069 Monkey and Banana(DP+LIS)
亲爱的派盘用户,我要向您表白!
Qt编写自定义控件-自绘电池
2022 the 8th China International "Internet +" college student innovation and entrepreneurship competition industry proposition track is open for registration!
How to add a gourd pie plate
Orcle创建用户+角色
【问题思考总结】为什么寄存器清零是在用户态进行的?
On the first day of the new year, 3000 Apache servers went down