当前位置:网站首页>C语言初阶——牛客网精选好题
C语言初阶——牛客网精选好题
2022-07-01 05:35:00 【小吕同学lc】
BC68 X形图案
描述
KiKi学习了循环,BoBo老师给他出了一系列打印图案的练习,该任务是打印用“*”组成的X形图案。
输入描述:
多组输入,一个整数(2~20),表示输出的行数,也表示组成“X”的反斜线和正斜线的长度。
输出描述:
针对每行输入,输出用“*”组成的X形图案。
#define _CRT_SECURE_NO_WARNINGS 1 //确保scanf函数能都在vs编译器下使用
#include <stdio.h>
int main()
{
char arr[20][20] = {
0 }; //创建二维数组
int i = 0;
int j = 0;
int a = 0;
while (scanf("%d", &a)!=EOF) //用循环来实现多组输入
{
for (i = 0;i < 20;i++) //将数组元素全部初始化为空格
{
for (j = 0;j < 20;j++)
{
arr[i][j] = ' ';
}
}
for (i = 0, j = 0;i < a, j < a;i++, j++) //正对角线元素改为‘*’
{
arr[i][j] = '*';
}
for (i = 0, j = a - 1;i < a, j >= 0;i++, j--) //反对角线元素改为‘*’
{
arr[i][j] = '*';
}
for (i = 0;i < a;i++) //打印出元素
{
for (j = 0;j < a;j++)
{
printf("%c", arr[i][j]);
}
printf("\n");
}
}
return 0;
}

BC54 获得月份天数
描述
KiKi想获得某年某月有多少天,请帮他编程实现。输入年份和月份,计算这一年这个月有多少天。
输入描述:
多组输入,一行有两个整数,分别表示年份和月份,用空格分隔。
输出描述:
针对每组输入,输出为一行,一个整数,表示这一年这个月有多少天。
#define _CRT_SECURE_NO_WARNINGS 1 //确保scanf函数能都在vs编译器下使用
#include <stdio.h>
int is_leap_yeay(int x) // 判断年份是否为闰年
{
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) // 大月为31天
{
printf("31\n");
}
else if (month == 2) //2月为特殊月,调用函数判断是否为闰年
{
int a = is_leap_yeay(year);
printf("%d\n", a);
}
else //其他情况为小月30天
{
printf("30\n");
}
}
return 0;
}
BC51 三角形判断
描述
KiKi想知道已经给出的三条边a,b,c能否构成三角形,如果能构成三角形,判断三角形的类型(等边三角形、等腰三角形或普通三角形)。
输入描述:
题目有多组输入数据,每一行输入三个a,b,c(0<a,b,c<1000),作为三角形的三个边,用空格分隔。
输出描述:
针对每组输入数据,输出占一行,如果能构成三角形,等边三角形则输出“Equilateral triangle!”,等腰三角形则输出“Isosceles triangle!”,其余的三角形则输出“Ordinary triangle!”,反之输出“Not a triangle!”。
#define _CRT_SECURE_NO_WARNINGS 1 //确保scanf函数能都在vs编译器下使用
#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)) //判断是否为三角形
{
if ((a == b && b!=c )|| (b == c && c!=a)|| a == c && c!=b) //判断是否为等腰三角形
{
printf("Isosceles triangle!\n");
}
else if (a == b && b == c && c == a) //判断是否为等边三角形
{
printf("Equilateral triangle!\n");
}
else
{
printf("Ordinary triangle!\n");
}
}
else
{
printf("Not a triangle!");
}
}
return 0;
}
边栏推荐
- Simple implementation of database connection pool
- Basic electrician knowledge 100 questions
- How to create a progress bar that changes color according to progress
- Introduction to 3D modeling and processing software Liu Ligang University of science and technology of China
- SSGSSRCSR区别
- POL8901 LVDS转MIPI DSI 支持旋转图像处理芯片
- JSON data comparer
- Idea start view project port
- [RootersCTF2019]babyWeb
- Trust guessing numbers game
猜你喜欢

数据库连接池的简单实现

多表操作-外键级联操作

Usage and principle of synchronized

JDBC common interview questions

How to create a progress bar that changes color according to progress
SSM的教务管理系统(免费源码获取)

Learn the customization and testing of fpga---ram IP from the bottom structure
![[RootersCTF2019]babyWeb](/img/b4/aa8f8e107a9dacbace72d4717b1834.png)
[RootersCTF2019]babyWeb

Multi table operation - foreign key cascade operation

tar命令
随机推荐
[QT] QT after addition, subtraction, multiplication and division, two decimal places are reserved
Introduction of 3D Modeling and Processing Software Liu Ligang, Chinese University of Science and Technology
[ffmpeg] [reprint] image mosaic: picture in picture with wheat
[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
Thread process foundation of JUC
Variable binding and deconstruction for rudimentary rust
0xc000007b应用程序无法正常启动解决方案(亲测有效)
数据库连接池的简单实现
Educational administration management system (free source code)
Use and principle of Park unpark
What is the at instruction set often used in the development of IOT devices?
CentOS 7使用yum安装PHP7.0
HDU - 1069 Monkey and Banana(DP+LIS)
Speed regulation and stroke control based on Ti drv8424 driving stepper motor
One click deployment of highly available emqx clusters in rainbow
实战:redux的基本使用
加密狗资料搜集
El cascade echo failed; El cascader does not echo
tese_ Time_ 2h
Data governance: metadata management implementation (Part IV)