Skip to content

Commit

Permalink
给我翻译翻译什么叫复习啊
Browse files Browse the repository at this point in the history
  • Loading branch information
SituChengxiang committed Jan 9, 2025
1 parent 3ec2901 commit cba2f34
Show file tree
Hide file tree
Showing 8 changed files with 550 additions and 84 deletions.
10 changes: 0 additions & 10 deletions C-exp/.vscode/launch.json

This file was deleted.

28 changes: 0 additions & 28 deletions C-exp/.vscode/tasks.json

This file was deleted.

92 changes: 46 additions & 46 deletions C-exp/exercise.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@
#include <stdlib.h>
#include <string.h>

// 定义学生结构体
typedef struct {
char name[100]; // 姓名字符串
char id[20]; // 学号字符串
float scores[3]; // 三门课程的成绩
} Student;
// 定义学生结构体
struct Student {
char name[100]; // 姓名字符串
char id[20]; // 学号字符串
float scores[3]; // 三门课程的成绩
};

int main() {
Student student;
FILE *file;

// 提示用户输入学生的姓名和学号
printf("请输入学生的姓名:");
fgets(student.name, sizeof(student.name), stdin);
student.name[strcspn(student.name, "\n")] = 0; // 去除换行符

printf("请输入学生的学号:");
fgets(student.id, sizeof(student.id), stdin);
student.id[strcspn(student.id, "\n")] = 0; // 去除换行符

// 提示用户输入三门课程的成绩
for (int i = 0; i < 3; i++) {
printf("请输入第%d门课程的成绩:", i + 1);
scanf("%f", &student.scores[i]);
}

// 清除输入缓冲区中的换行符
getchar();

// 打开文件用于写入
file = fopen("d:\\aaa.txt", "w");
if (file == NULL) {
printf("无法打开文件!");
return 1;
}

// 将学生信息写入文件
fprintf(file, "姓名:%s 学号:%s", student.name, student.id);
for (int i = 0; i < 3; i++) {
fprintf(file, "第%d门课程成绩:%f", i + 1, student.scores[i]);
}

// 关闭文件
fclose(file);

printf("学生信息已成功写入到d:\\aaa.txt文件中。");

return 0;
struct Student student;
FILE *file;

// 提示用户输入学生的姓名和学号
printf("请输入学生的姓名:");
fgets(student.name, sizeof(student.name), stdin);
student.name[strcspn(student.name, "\n")] = 0; // 去除换行符

printf("请输入学生的学号:");
fgets(student.id, sizeof(student.id), stdin);
student.id[strcspn(student.id, "\n")] = 0; // 去除换行符

// 提示用户输入三门课程的成绩
for (int i = 0; i < 3; i++) {
printf("请输入第%d门课程的成绩:", i + 1);
scanf("%f", &student.scores[i]);
}

// 清除输入缓冲区中的换行符
getchar();

// 打开文件用于写入
file = fopen("d:\\aaa.txt", "w");
if (file == NULL) {
printf("无法打开文件!");
return 1;
}

// 将学生信息写入文件
fprintf(file, "姓名:%s 学号:%s", student.name, student.id);
for (int i = 0; i < 3; i++) {
fprintf(file, "第%d门课程成绩:%f", i + 1, student.scores[i]);
}

// 关闭文件
fclose(file);

printf("学生信息已成功写入到d:\\aaa.txt文件中。");

return 0;
}
Empty file removed C-exp/test/111.c
Empty file.
21 changes: 21 additions & 0 deletions C-exp/test/CppProperties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"configurations": [
{
"inheritEnvironments": [
"msvc_x64"
],
"name": "x64-Debug",
"includePath": [
"${env.INCLUDE}",
"${workspaceRoot}\\**"
],
"defines": [
"WIN32",
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"intelliSenseMode": "windows-msvc-x64"
}
]
}
28 changes: 28 additions & 0 deletions C-exp/test/a20219.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
#include <string.h>
int main()
{
int i, j;
char *name[] = {"HangZhou", "ShangHai", "GuangZhou", "BeiJing", "ShenZhen"};
char *pstr;

// 冒泡排序算法对字符串数组进行升序排列
for (i = 0; i < 4; i++) { // 外层循环控制遍历次数
for (j = 0; j < 4 - i; j++) { // 内层循环比较相邻元素
if (strcmp(name[j], name[j + 1]) < 0) { // 如果前一个字符串大于后一个字符串,则交换
pstr = name[j];
name[j] = name[j + 1];
name[j + 1] = pstr;
}
}
}

// 输出排序后的字符串数组
for (i = 0; i < 5; i++)
printf("%c\n", *name[i]); // 使用 %s 格式符打印字符串

for (i = 0; i < 5; i++)
printf("%c\n", name[i][1]); // 使用 %s 格式符打印字符串

return 0;
}
25 changes: 25 additions & 0 deletions C-exp/test/algorithm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdio.h>

void bubbleSort(int arr[], int n) {
int i, j, temp;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
// ½»»» arr[j] ºÍ arr[j+1]
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}

int main() {
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(arr)/sizeof(arr[0]);
bubbleSort(arr, n);
printf("Sorted array: \n");
for (int i=0; i < n; i++)
printf("%d ", arr[i]);
return 0;
}
Loading

0 comments on commit cba2f34

Please sign in to comment.