From f25d1ac3e0ce11187ed957933416cd5b8995cc5f Mon Sep 17 00:00:00 2001 From: smallkun Date: Thu, 20 Feb 2025 23:18:47 +0800 Subject: [PATCH] Auto commit --- 2207/C语言同步练习.md | 299 ++++++++++++++++++ .../1.c => C语言同步练习源码/1.选择结构-1.c} | 0 .../2.c => C语言同步练习源码/1.选择结构-2.c} | 0 .../3.c => C语言同步练习源码/1.选择结构-3.c} | 2 +- .../4.c => C语言同步练习源码/1.选择结构-4.c} | 2 +- .../1.c => C语言同步练习源码/2.循环结构-1.c} | 0 6 files changed, 301 insertions(+), 2 deletions(-) create mode 100644 2207/C语言同步练习.md rename 2207/{C语言同步练习/选择结构/1.c => C语言同步练习源码/1.选择结构-1.c} (100%) rename 2207/{C语言同步练习/选择结构/2.c => C语言同步练习源码/1.选择结构-2.c} (100%) rename 2207/{C语言同步练习/选择结构/3.c => C语言同步练习源码/1.选择结构-3.c} (95%) rename 2207/{C语言同步练习/选择结构/4.c => C语言同步练习源码/1.选择结构-4.c} (96%) rename 2207/{C语言同步练习/循环结构/1.c => C语言同步练习源码/2.循环结构-1.c} (100%) diff --git a/2207/C语言同步练习.md b/2207/C语言同步练习.md new file mode 100644 index 0000000..3e8a84e --- /dev/null +++ b/2207/C语言同步练习.md @@ -0,0 +1,299 @@ +## 选择结构 + +### 选择结构-1 + +![image-20250220225958223](https://yp.smallkun.cn/markdown/image-20250220225958223.png!compress) + +```c +#include + +/* +if(条件){ + 复合语句(条件为真时执行) +}else{ + 复合语句(条件为假时执行) +} +*/ +int main(void){ + + int x, y, z, t;//定义三个整型变量 + //数据类型 变量名1, 变量名2; + scanf("%d%d%d", &x, &y, &z); + if(x > y){ + t = x; + x = y; + y = t; + }//实现x和y比较 大数放y位置 + if(y > z){ + t = y; + y = z; + z = t; + }//实现y和z比较 大数放z位置 z为三个数字中最大数 + if(x > y){ + t = x; + x = y; + y = t; + } + printf("%d %d %d\n", x, y, z); + + return 0; +} + +``` + +### 选择结构-2 + +![image-20250220230052521](https://yp.smallkun.cn/markdown/image-20250220230052521.png!compress) + +```c +#include + +int main(void){ + + + int a; + + scanf("%d", &a); + printf("该数的位数为%d\n", + (a/10==0?1:(a/100==0?2:(a/1000==0?3:(a/10000==0?4:5))))); + printf("%d", a%10); + if(a%100/10 != 0){ + printf("%d", a%100/10); + } + if(a%1000/100 != 0){ + printf("%d", a%1000/100); + } + if(a%10000/1000 != 0){ + printf("%d", a%10000/1000); + } + if(a/10000 != 0){ + printf("%d", a/10000); + } + printf("\n"); + return 0; +} + +``` + +### 选择结构-3 + +![image-20250220230133563](https://yp.smallkun.cn/markdown/image-20250220230133563.png!compress) + +```c +#include + +int main(void){ + + float a, b, result; + int flag; + printf("请输入两个数字:"); + scanf("%f %f", &a, &b); + printf("请输入您要进行的操作(1.做加法 2.做乘法 3.做除法):"); + scanf("%d", &flag); + switch(flag){ + case 1:result = a+b;break; + case 2:result = a*b;break; + case 3:result = a/b;break; + } + printf("结果为%f\n", result); + + return 0; +} + +``` + +### 选择结构-4 + +![image-20250220230626411](https://yp.smallkun.cn/markdown/image-20250220230626411.png!compress) + +```c +#include + +int main(void){ + + int year, month, day, days=0; + + scanf("%d-%d-%d", &year, &month, &day); + days+=day; + //1 3 5 7 8 10 12 + //从前一个月开始依次 + switch(month-1){ + case 11:days+=30; + case 10:days+=31; + case 9:days+=30; + case 8:days+=31; + case 7:days+=31; + case 6:days+=30; + case 5:days+=31; + case 4:days+=30; + case 3:days+=31; + case 2:days+=28; + case 1:days+=31; + } + if(month>3 && (year%4==0&&year%100!=0 || year%400==0)){ + days++; + } + printf("%d\n", days); + + + return 0; +} +``` + +--- + +## 循环结构 + +### 循环结构-1 + +![image-20250220230645828](https://yp.smallkun.cn/markdown/image-20250220230645828.png!compress) + +```c +#include + + +/* +1.解决字符的循环输入 +while((ch=getchar())!='\n') + +2.判断字符类型 +ASCALL码范围 + +*/ +int main(){ + + char ch; + int l, d, o;//l字母的个数 d为数字个数 o为其他字符个数 + l=d=o=0; + while((ch=getchar()) != '\n'){ + if(ch >= 'a' && ch<='z' || ch >= 'A' && ch<='Z' ){ + l++; + }else if(ch >= '0' && ch <= '9'){ + d++; + }else{ + o++; + } + } + printf("字母个数:%d 数字个数:%d 其他个数%d\n", l, d, o); + + return 0; +} +``` + +### 循环结构-2 + +![image-20250220230945704](https://yp.smallkun.cn/markdown/image-20250220230945704.png!compress) + +```c + +``` + +### 循环结构-3 + +![image-20250220230952843](https://yp.smallkun.cn/markdown/image-20250220230952843.png!compress) + +```c +``` + +### 循环结构-4 + +![image-20250220231000056](https://yp.smallkun.cn/markdown/image-20250220231000056.png!compress) + +```c +``` + +### 循环结构-5 + +![image-20250220231006104](https://yp.smallkun.cn/markdown/image-20250220231006104.png!compress) + +```c +``` + +### 循环结构-6 + +![image-20250220231012110](https://yp.smallkun.cn/markdown/image-20250220231012110.png!compress) + +```c +``` + +### 循环结构-7 + +![image-20250220231022607](https://yp.smallkun.cn/markdown/image-20250220231022607.png!compress) + +```c +``` + +### 循环结构-8 + +![image-20250220231027969](https://yp.smallkun.cn/markdown/image-20250220231027969.png!compress) + +```c +``` + +### 循环结构-9 + +![image-20250220231034218](https://yp.smallkun.cn/markdown/image-20250220231034218.png!compress) + +```c +``` + +### 循环结构-10 + +![image-20250220231039716](https://yp.smallkun.cn/markdown/image-20250220231039716.png!compress) + +```c +``` + +--- + +## 数组 + +### 数组-1 + +![image-20250220231426147](https://yp.smallkun.cn/markdown/image-20250220231426147.png!compress) + + + +### 数组-2 + +![image-20250220231434409](https://yp.smallkun.cn/markdown/image-20250220231434409.png!compress) + + + +### 数组-3 + +![image-20250220231441384](https://yp.smallkun.cn/markdown/image-20250220231441384.png!compress) + + + +### 数组-4 + +![image-20250220231447834](https://yp.smallkun.cn/markdown/image-20250220231447834.png!compress) + + + +### 数组-5 + +![image-20250220231704799](https://yp.smallkun.cn/markdown/image-20250220231704799.png!compress) + +--- + +## 函数 + + + +## 指针 + + + +## 编译预处理 + + + +## 结构体 + + + +## 文件 + +## \ No newline at end of file diff --git a/2207/C语言同步练习/选择结构/1.c b/2207/C语言同步练习源码/1.选择结构-1.c similarity index 100% rename from 2207/C语言同步练习/选择结构/1.c rename to 2207/C语言同步练习源码/1.选择结构-1.c diff --git a/2207/C语言同步练习/选择结构/2.c b/2207/C语言同步练习源码/1.选择结构-2.c similarity index 100% rename from 2207/C语言同步练习/选择结构/2.c rename to 2207/C语言同步练习源码/1.选择结构-2.c diff --git a/2207/C语言同步练习/选择结构/3.c b/2207/C语言同步练习源码/1.选择结构-3.c similarity index 95% rename from 2207/C语言同步练习/选择结构/3.c rename to 2207/C语言同步练习源码/1.选择结构-3.c index 6a75b09..fe5bb10 100644 --- a/2207/C语言同步练习/选择结构/3.c +++ b/2207/C语言同步练习源码/1.选择结构-3.c @@ -1,6 +1,6 @@ #include -int main(){ +int main(void){ float a, b, result; int flag; diff --git a/2207/C语言同步练习/选择结构/4.c b/2207/C语言同步练习源码/1.选择结构-4.c similarity index 96% rename from 2207/C语言同步练习/选择结构/4.c rename to 2207/C语言同步练习源码/1.选择结构-4.c index 7443d2e..074acfe 100644 --- a/2207/C语言同步练习/选择结构/4.c +++ b/2207/C语言同步练习源码/1.选择结构-4.c @@ -1,6 +1,6 @@ #include -int main(){ +int main(void){ int year, month, day, days=0; diff --git a/2207/C语言同步练习/循环结构/1.c b/2207/C语言同步练习源码/2.循环结构-1.c similarity index 100% rename from 2207/C语言同步练习/循环结构/1.c rename to 2207/C语言同步练习源码/2.循环结构-1.c