各位CSDN的uu们你们好呀,今天小雅兰的内容又到了我们的复习啦,那么还是刷题噢,话不多说,让我们进入C语言的世界吧


BC55 简单计算器

BC56 线段图案

BC57 正方形图案

BC58 直角三角形图案

BC59 翻转直角三角形图案

BC60 带空格直角三角形图案

BC61 金字塔图案

BC62 翻转金字塔图案

BC63 菱形图案

BC64 K形图案

BC65 箭形图案

BC66 反斜线形图案

BC67 正斜线形图案

BC68 X形图案

BC69 空心正方形图案

BC70 空心三角形图案


题目仍然来源于牛客网

编程语言初学训练营_在线编程+题解_牛客题霸_牛客网


#include //精度尽量保持高//这个题使用float精度不满足要求int main(){double n1 = 0.0;double n2 = 0.0;char op = 0;while (scanf("%lf%c%lf", &n1, &op, &n2) != EOF){switch (op){case '+':printf("%.4lf+%.4lf=%.4lf", n1, n2, n1 + n2);break;case '-':printf("%.4lf-%.4lf=%.4lf", n1, n2, n1 - n2);break;case '*':printf("%.4lf*%.4lf=%.4lf", n1, n2, n1 * n2);break;case '/':{if (n2 == 0.0){printf("Wrong!Division by zero!\n");}else{printf("%.4lf/%.4lf=%.4lf", n1, n2, n1 / n2);}break;}default:printf("Invalid operation!\n");break;}}return 0;}

1. 多组输入

2. 按照格式接收,按照要求编写代码就行

3. switch语句

#include int main(){int n=0;while(scanf("%d ",&n)!=EOF){int i=0;for(i=0;i<n;i++){printf("*");}printf("\n");}return 0;}

1. 多组输入

2. 每次打印一个*,按照输入的个数打印后换行就行

#include int main() {int n = 0;while (scanf("%d", &n) != EOF){int i = 0;//确定行数for (i = 0; i < n; i++){int j = 0;//每一行的打印,打印n组*+空格for (j = 0; j < n; j++){printf("* ");}printf("\n");}}return 0;}

1. 多组输入

2. 每组是由n组*+空格组成

#includeint main(){int n = 0;while(scanf("%d",&n) !=EOF){int i = 0;//控制行数for(i=1;i <=n;i++){//每一行int j = 0;for(j=1;j <=i;j++){printf("* ");}printf("\n");}}return 0;}

1. 多组输入

2. 每一行的输出要计算清楚

#include int main(){int n = 0;while (scanf("%d", &n) != EOF){int i = 0;for (i = n; i >= 1; i--){int j = 0;for (j = i; j >= 1; j--){//这里注意空格printf("* ");}printf("\n");}}return 0;}

1. 多组输入

2. 每两个*中间有空格,要注意

3. 控制好一行输出的内容

#include int main(){int n = 0;while (scanf("%d", &n) != EOF){int i = 0;//行数控制for (i = 0; i < n; i++){//空格int j = 0;for (j = 0; j < n - 1 - i; j++){printf("");}//*for (j = 0; j <= i; j++){printf("* ");}printf("\n");}}return 0;}

另一种写法:

在红色三角范围内的每个坐标上,横纵坐标之和小于n-1。

#include int main(){int n = 0;while (scanf("%d", &n) != EOF){int i = 0;int j = 0;//行数for (i = 0; i < n; i++){//一行for (j = 0; j < n; j++){//行和列的和//这里可以把行数和列数标出来就能看明白if (i + j < n - 1){printf("");}else{printf("* ");}}printf("\n");}}return 0;}

#include int main(){int n = 0;while (scanf("%d", &n) != EOF){int i = 0;for (i = 0; i < n; i++){//一行int j = 0;//空格for (j = 0; j < n - 1 - i; j++){printf(" ");}//*for (j = 0; j <= i; j++){printf("* ");}printf("\n");}}return 0;}

1. 多组输入

2. 每一行的前边应该是空格,后边是*+空格,控制好个数就行

#include int main(){int n = 0;while (scanf("%d", &n) != EOF){int i = 0;for (i = 0; i < n; i++){//一行int j = 0;for (j = 0; j < i; j++){printf(" ");}for (j = 0; j < n - i; j++){printf("* ");}printf("\n");}}return 0;}

1. 多组输入

2. 控制好行数,控制好每一行前面的空格数

#include int main(){int n = 0;while (scanf("%d", &n) != EOF){int i = 0;//上for (i = 0; i < n; i++){//一行int j = 0;for (j = 0; j < n - i; j++){printf(" ");}for (j = 0; j <= i; j++){printf("* ");}printf("\n");}//下for (i = 0; i <= n; i++){//一行int j = 0;for (j = 0; j < i; j++){printf(" ");}for (j = 0; j <= n - i; j++){printf("* ");}printf("\n");}}return 0;}

1. 首先把菱形的打印分为上下2个部分

2. 上下分别控制好行数和空格的个数

3. 多组输入

#include //这个题好坑int main(){int n = 0;//如果输入的是n,其实每行打印n+1组字符(*和空格)while (scanf("%d", &n) != EOF){int i = 0;for (i = n; i >= 0; i--){int j = 0;for (j = 0; j <= i; j++){printf("* ");}//*的后面还有空格-这个比较坑for (j = i; j < n; j++){printf(" ");}printf("\n");}for (i = 1; i <= n; i++){int j = 0;for (j = 0; j <= i; j++){printf("* ");}//*的后边还有空格-这个比较坑for (j = i; j < n; j++){printf(" ");}printf("\n");}}return 0;}

1. 多行输入

2. 图形的打印分为上下2个部分

3. 每一行的打印完,后边还有空格,可能牛客网的题目处理不严谨,在题目中也没体现,怎么都做不出来,不过选中输出样例,会发现后边有空格。

#include int main(){int n = 0;while(scanf("%d",&n) !=EOF){//上n行int i = 0;for (i = n; i > 0; i--){int j = 0;for (j = 0; j < i; j++){printf("");}for (j = 0; j  0; i--){int j = 0;for (j = 0; j < n + 1 - i; j++){printf("");}for (j = 0; j < i; j++){printf("*");}printf("\n");}}return 0;}

1. 多组输入

2. 图形分为上下2个部分打印

3. 每一行前面是空格,后边是*(前面2个空格为1组)

#include //方法1-传统求解方式int main(){int n = 0;while(scanf("%d",&n) !=EOF){int i = 0;for(i=0;i<n;i++){//空格int j = 0;for(j=0;j<i;j++){printf(" ");}//*printf("*");//注意*后边的空格for(j=i+1;j<n;j++){printf(" ");}printf("\n");}}return 0;}

另一种方法:

#include //找出规律int main(){int n = 0;while (scanf("%d", &n) != EOF){int i = 0;for (i = 0; i < n; i++){int j = 0;for (j = 0; j < n; j++){if (i == j)printf("*");elseprintf(" ");}printf("\n");}}return 0;}

1. 多组输入

2. 控制好每行的打印,前面是空格,后边是*

3. *的后边还有空格,一行要打印够n和字符的

4. 方法2找出打印*的行号和列号的规律是 i==j

#include //代码1int main(){int n = 0;while(scanf("%d",&n) != EOF){int i = 0;//行for(i=0;i<n;i++){//空格int j = 0;for(j=0;j<n-1-i;j++){printf(" ");}//*printf("*");//空格for(j=n-i;j<n;j++){printf(" ");}printf("\n");}}return 0;}

另一种方法:

#include //代码2int main(){int n = 0;while (scanf("%d", &n) != EOF){int i = 0;for (i = 0; i < n; i++){int j = 0;for (j = 0; j < n; j++){if (i + j == n - 1)printf("*");elseprintf(" ");}printf("\n");}}return 0;}

1. 多组输入

2. 控制好每行的打印,前面是空格,后边是*

3. *的后边还有空格,一行要打印够n和字符的

4. 方法2找出打印*的行号和列好的规律是i+j == n-1

#include int main(){int n = 0;while (scanf("%d", &n) != EOF){int i = 0;int j = 0;for (i = 0; i < n; i++){for (j = 0; j < n; j++){if (i == j)printf("*");else if (i + j == n - 1)//因为行和列是从0开始的printf("*");elseprintf(" ");}printf("\n");}}return 0;}

1. 多组输入

2. 找出打印*的打印空格的规律,直接按照规律实现就行

#include int main(){int n = 0;while (scanf("%d", &n) != EOF){int i = 0;int j = 0;for (i = 0; i < n; i++){for (j = 0; j < n; j++){if (i == 0 || i == n - 1)printf("* ");else if (j == 0 || j == n - 1)printf("* ");elseprintf("");}printf("\n");}}return 0;}

1. 多行输入

2. 找出打印*的规律,剩余的打印空格,直接打印就行

#include int main(){int n = 0;while (scanf("%d", &n) != EOF){int i = 0;for (i = 1; i <= n; i++){int j = 0;for (j = 1; j <= n; j++){if ((i == j) || (j == 1) || (i == n)){printf("* ");}else{printf("");}}printf("\n");}}return 0;}

1. 多组输入。

2. 找出打印*的规律,然后直接按照要求打印就行。


好啦,小雅兰今天的复习内容就到这里啦,今天做的一般都是图案题,之后还要继续加油呀!!!