Browse Source

增加了部分题目

Pchen. 5 months ago
parent
commit
1b3374dc70
44 changed files with 1200 additions and 817 deletions
  1. 28 20
      code/CPU类的定义和使用——9-02.cpp
  2. 18 13
      code/Fibonacci数列.c
  3. 46 39
      code/二维坐标Point类派生三维空间坐标点类Point3D.cpp
  4. 15 24
      code/二维整型数组的“最大点”.c
  5. 31 40
      code/二维整型数组的“最小点”.c
  6. 60 0
      code/几何图形的继承和派生(有输入).cpp
  7. 21 51
      code/删除重复字符排序字符串.c
  8. 16 25
      code/判断两个数组是否包含相同元素.c
  9. 21 19
      code/判断可逆素数.c
  10. 21 0
      code/去大写英文字母(要求用指针做).c
  11. 17 21
      code/合并字符串.c
  12. 55 0
      code/合并有序数组.c
  13. 15 15
      code/回文判断.c
  14. 53 0
      code/圆类的定义使用和成员函数重载与圆环类的继承.cpp
  15. 63 60
      code/坐标点Point的运算符重载.cpp
  16. 10 11
      code/字符串复制.c
  17. 25 13
      code/字符串比较2.c
  18. 40 0
      code/字符串逆序输出.c
  19. 31 36
      code/定义一个长方形Rect类再派生出长方体类Cub.cpp
  20. 22 32
      code/定义复数类的加法与减法(运算符+-重载).cpp
  21. 22 37
      code/定义并实现一个学生类(Student).cpp
  22. 65 40
      code/定义并实现一个银行类(Bank).cpp
  23. BIN
      code/实现客户机client类.zip
  24. 10 20
      code/寻找完全数.c
  25. 22 39
      code/序列的中间数.c
  26. 22 14
      code/排序-sort指针例子.c
  27. 11 34
      code/数组元素循环右移问题(有样例代码).c
  28. 1 1
      code/数组逆序存放.c
  29. 19 14
      code/整数各位数字求和.c
  30. 2 1
      code/整数合并.c
  31. 117 0
      code/时间类Time的编写.cpp
  32. 9 18
      code/最大公约数和最小公倍数.c
  33. 24 18
      code/正整数的打印.c
  34. 28 0
      code/求公式近似值formula.c
  35. 24 25
      code/求差集.c
  36. 15 0
      code/求最大最小整数.c
  37. 20 20
      code/点类定义和使用.cpp
  38. 25 29
      code/狗的定义和使用(继承中的构造和析构).cpp
  39. 57 0
      code/用静态数据成员和静态函数统计猫的数量——11-01.cpp
  40. 0 1
      code/矩阵乘法.c
  41. 11 9
      code/矩阵转置.c
  42. 46 28
      code/船和卡车的重量计算——友元函数——11-02.cpp
  43. 5 32
      code/输出圆圈报数退出的最后号码.c
  44. 37 18
      code/项目三-指定区间[A,B]之间的素数和.c

+ 28 - 20
code/CPU类的定义和使用——9-02.cpp

@@ -1,5 +1,5 @@
 #include <iostream>
-using namespace std;
+#include <string>
 
 enum CPU_Rank { P1 = 1, P2, P3, P4, P5, P6, P7 };
 
@@ -10,40 +10,48 @@ private:
     float voltage;
 
 public:
-    // 构造函数
     CPU(CPU_Rank r = P1, int f = 100, float v = 2.0) : rank(r), frequency(f), voltage(v) {
-        cout << "one CPU is created!" << endl;
+        std::cout << "one CPU is created!" << std::endl;
     }
 
-    // 析构函数
     ~CPU() {
-        cout << "one CPU is distoried!" << endl;
+        std::cout << "one CPU is distoried!" << std::endl;
     }
 
-    // 运行
-    void run() {
-        cout << "CPU is running!" << endl;
+    void display() {
+        std::string rank_str;
+        switch (rank) {
+            case P1: rank_str = "P1"; break;
+            case P2: rank_str = "P2"; break;
+            case P3: rank_str = "P3"; break;
+            case P4: rank_str = "P4"; break;
+            case P5: rank_str = "P5"; break;
+            case P6: rank_str = "P6"; break;
+            case P7: rank_str = "P7"; break;
+            default: rank_str = "Unknown Rank";
+        }
+
+        std::cout << "rank: " << rank_str << std::endl;
+        std::cout << "frequency: " << frequency << std::endl;
+        std::cout << "voltage: " << voltage << std::endl;
     }
 
-    // 停止
-    void stop() {
-        cout << "CPU stop!" << endl;
+    void run() {
+        std::cout << "CPU is running!" << std::endl;
     }
 
-    // 显示CPU信息
-    void display() const {
-        cout << "rank:P" << rank << endl;
-        cout << "frequency:" << frequency << endl;
-        cout << "voltage:" << voltage << endl;
+    void stop() {
+        std::cout << "CPU stop!" << std::endl;
     }
 };
 
 int main() {
-    int f;
-    float v;
-    cin >> f >> v;
+    int rank_input, frequency_input;
+    float voltage_input;
+    std::cin >> rank_input >> frequency_input >> voltage_input;
+
+    CPU myCPU(static_cast<CPU_Rank>(rank_input), frequency_input, voltage_input);
 
-    CPU myCPU(P6, f, v);
     myCPU.run();
     myCPU.display();
     myCPU.stop();

+ 18 - 13
code/Fibonacci数列.c

@@ -1,16 +1,21 @@
 #include <stdio.h>
 
+// 函数用递归的方式计算斐波那契数列的第n个数字
+int fibonacci(int n) {
+    if (n <= 1) {
+        return n;
+    }
+    return fibonacci(n - 1) + fibonacci(n - 2);
+}
+
 int main() {
-	int n;
-	scanf("%d",&n);
-	
-	int i,x,y=0,z=1;
-	for(i=1;i<=n;i++) {
-		x = y;
-		y = z;
-		z += x;
-	}
-	printf("%d",y);
-	
-	return 0;
-}
+    int n;
+    
+    // 读取输入
+    scanf("%d", &n);
+    
+    // 计算并输出第n个斐波那契数
+    printf("%d\n", fibonacci(n));
+
+    return 0;
+}

+ 46 - 39
code/二维坐标Point类派生三维空间坐标点类Point3D.cpp

@@ -1,53 +1,60 @@
 #include <iostream>
 #include <cmath>
-using namespace std;
 
+// 定义二维平面坐标点类
 class Point {
 protected:
-	double x, y;
-	
+    double x, y;
+
 public:
-	Point() : x(0), y(0) {}
-	
-	Point(double x, double y) : x(x), y(y) {}
-	
-	double getx() {
-		return x;
-	}
-	
-	double gety() {
-		return y;
-	}
-	
-	double dist(const Point& p) {
-		return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
-	}
+    // 构造函数1:创建原点(0, 0)
+    Point() : x(0), y(0) {}
+
+    // 构造函数2:带参数
+    Point(double x, double y) : x(x), y(y) {}
+
+    double getx() const {
+        return x;
+    }
+
+    double gety() const {
+        return y;
+    }
+
+    double dist(const Point& p) const {
+        return std::sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
+    }
 };
 
+// 定义三维空间坐标点类,继承自二维平面坐标点类
 class Point3D : public Point {
 private:
-	double z;
-	
+    double z;
+
 public:
-	Point3D() : Point(), z(0) {}
-	
-	Point3D(double x, double y, double z) : Point(x, y), z(z) {}
-	
-	double getz() {
-		return z;
-	}
-	
-	double dist(const Point3D& p) {
-		return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) + (z - p.z) * (z - p.z));
-	}
+    // 构造函数1:创建原点(0, 0, 0)
+    Point3D() : Point(), z(0) {}
+
+    // 构造函数2:带参数
+    Point3D(double x, double y, double z) : Point(x, y), z(z) {}
+
+    double getz() const {
+        return z;
+    }
+
+    double dist(const Point3D& p) const {
+        return std::sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) + (z - p.z) * (z - p.z));
+    }
 };
 
 int main() {
-	Point3D A;
-	Point3D B(4, 5.6, 7.8);
-	
-	double distance = A.dist(B);
-	cout << "|A-B|=" << distance << endl;
-	
-	return 0;
-}
+    // 创建A点和B点
+    Point3D A(0, 0, 0);
+    Point3D B(4, 5.6, 7.8);
+
+    // 计算A点和B点之间的距离并输出
+    double distance = A.dist(B);
+    std::cout << "|A-B|=" << distance << std::endl;
+
+    return 0;
+}

+ 15 - 24
code/二维整型数组的“最大点”.c

@@ -1,49 +1,40 @@
 #include <stdio.h>
 
 int main() {
-    int n, m, i, j;
-    // 璇诲彇浜岀淮鏁扮粍鐨勮�鏁板拰鍒楁暟
+    int n, m;
+    int i,j;
     scanf("%d %d", &n, &m);
 
-    int arr[n][m];
-    // 璇诲彇浜岀淮鏁扮粍鐨勫厓绱�
+    int arr[10][10];
+
+    // 读取二维数组元素
     for (i = 0; i < n; i++) {
         for (j = 0; j < m; j++) {
             scanf("%d", &arr[i][j]);
         }
     }
 
-    // 鏌ユ壘姣忚�鐨勬渶澶у€煎拰鏈€澶у€兼墍鍦ㄧ殑鍒�
-    int row_max[n];
-    int row_max_col[n];
+    // 查找每行最大值和每列最大值
+    int row_max[10] = {0};
+    int col_max[10] = {0};
+
     for (i = 0; i < n; i++) {
-        row_max[i] = arr[i][0];
-        row_max_col[i] = 0;
-        for (j = 1; j < m; j++) {
+        for (j = 0; j < m; j++) {
             if (arr[i][j] > row_max[i]) {
                 row_max[i] = arr[i][j];
-                row_max_col[i] = j;
             }
-        }
-    }
-
-    // 鏌ユ壘姣忓垪鐨勬渶澶у€�
-    int col_max[m];
-    for (j = 0; j < m; j++) {
-        col_max[j] = arr[0][j];
-        for (i = 1; i < n; i++) {
             if (arr[i][j] > col_max[j]) {
                 col_max[j] = arr[i][j];
             }
         }
     }
 
-    // 鏌ユ壘鏈€澶х偣
+    // 输出"最大点"
     for (i = 0; i < n; i++) {
-        int max_val = row_max[i];
-        int col_idx = row_max_col[i];
-        if (max_val == col_max[col_idx]) {
-            printf("%d %d %d\n", max_val, i + 1, col_idx + 1);
+        for (j = 0; j < m; j++) {
+            if (arr[i][j] == row_max[i] && arr[i][j] == col_max[j]) {
+                printf("%d %d %d\n", arr[i][j], i + 1, j + 1); // 注意行列从1开始计数
+            }
         }
     }
 

+ 31 - 40
code/二维整型数组的“最小点”.c

@@ -1,58 +1,49 @@
 #include <stdio.h>
 
-void find_minimum_points(int matrix[][10], int n, int m) {
-    int min_in_row[n], min_in_col[m];
-    int i,j;
-    
-    // 初始化最小值数组为最大整数
-    for (i = 0; i < n; ++i) {
-        min_in_row[i] = 2147483647;
-    }
-    for (j = 0; j < m; ++j) {
-        min_in_col[j] = 2147483647;
-    }
+int main() {
+    int n, m;
+    int  i,j;
+    scanf("%d %d", &n, &m);
 
-    // 找到每行的最小值
-    for (i = 0; i < n; ++i) {
-        for (j = 0; j < m; ++j) {
-            if (matrix[i][j] < min_in_row[i]) {
-                min_in_row[i] = matrix[i][j];
-            }
+    int arr[10][10];
+
+    // 读取二维数组元素
+    for (i = 0; i < n; i++) {
+        for (j = 0; j < m; j++) {
+            scanf("%d", &arr[i][j]);
         }
     }
 
-    for (j = 0; j < m; ++j) {
-        for (i = 0; i < n; ++i) {
-            if (matrix[i][j] < min_in_col[j]) {
-                min_in_col[j] = matrix[i][j];
+    // 查找每行最小值和每列最小值
+    int row_min[10] = {0};
+    int col_min[10] = {0};
+
+    for (i = 0; i < n; i++) {
+        row_min[i] = arr[i][0]; // 初始化为第一列的值
+        for (j = 1; j < m; j++) {
+            if (arr[i][j] < row_min[i]) {
+                row_min[i] = arr[i][j];
             }
         }
     }
-
-    for (i = 0; i < n; ++i) {
-        for (j = 0; j < m; ++j) {
-            if (matrix[i][j] == min_in_row[i] && matrix[i][j] == min_in_col[j]) {
-                printf("%d %d %d\n", matrix[i][j], i + 1, j + 1);
+    
+    for (j = 0; j < m; j++) {
+        col_min[j] = arr[0][j]; // 初始化为第一行的值
+        for (i = 1; i < n; i++) {
+            if (arr[i][j] < col_min[j]) {
+                col_min[j] = arr[i][j];
             }
         }
     }
-}
-
-int main() {
-    int n,m,i,j;
-    scanf("%d %d", &n, &m);
 
-    int matrix[10][10];
-
-    for (i = 0; i < n; ++i) {
-        for (j = 0; j < m; ++j) {
-            scanf("%d", &matrix[i][j]);
+    // 输出"最小点"
+    for (i = 0; i < n; i++) {
+        for (j = 0; j < m; j++) {
+            if (arr[i][j] == row_min[i] && arr[i][j] == col_min[j]) {
+                printf("%d %d %d\n", arr[i][j], i + 1, j + 1); // 注意行列从1开始计数
+            }
         }
     }
 
-    // 查找二维数组的最小点
-    find_minimum_points(matrix, n, m);
-
     return 0;
 }
-

+ 60 - 0
code/几何图形的继承和派生(有输入).cpp

@@ -0,0 +1,60 @@
+#include <iostream>
+#include <cmath>
+#include <iomanip>
+#define pi 3.14
+
+class Shape {
+public:
+    virtual double GetArea() const = 0;
+    virtual ~Shape() {}
+};
+
+class Circle : public Shape {
+private:
+    double radius;
+public:
+    Circle(double r) : radius(r) {}
+    double GetArea() const override {
+        return pi * radius * radius;
+    }
+};
+
+class Rectangle : public Shape {
+private:
+    double length;
+    double width;
+public:
+    Rectangle(double l, double w) : length(l), width(w) {}
+    double GetArea() const override {
+        return length * width;
+    }
+};
+
+class Square : public Rectangle {
+public:
+    Square(double side) : Rectangle(side, side) {}
+};
+
+int main() {
+    double radius;
+    std::cin >> radius;
+    Circle* circle = new Circle(radius);
+    std::cout << "The area of the Cirele is:" << circle->GetArea() << std::endl;
+    delete circle;
+
+
+    double length, width;
+    std::cin >> length >> width;
+    Rectangle* rectangle = new Rectangle(length, width);
+    std::cout << "The area of the Recanale is:" << rectangle->GetArea() << std::endl;
+    delete rectangle;
+
+
+    double side;
+    std::cin >> side;
+    Square* square = new Square(side);
+    std::cout << "The area of the Recanale is:" << square->GetArea() << std::endl;
+    delete square;
+
+    return 0;
+}

+ 21 - 51
code/删除重复字符排序字符串.c

@@ -1,65 +1,35 @@
 #include <stdio.h>
 #include <string.h>
 
-// 杈呭姪鍑芥暟锛氫氦鎹�袱涓�瓧绗�
-void swap(char *a, char *b) {
-    char temp = *a;
-    *a = *b;
-    *b = temp;
-}
+// 排序并删除重复字符
+void sortAndRemoveDuplicates(char *str) {
+    int i, j, k; // 用于循环的变量
+    
+    // 记录每个字符出现的次数
+    int count[256] = {0};
 
-// 杈呭姪鍑芥暟锛氬揩閫熸帓搴�
-void quicksort(char arr[], int low, int high) {
-    if (low < high) {
-        int pivot = arr[high];
-        int i = (low - 1), j;
-        for (j = low; j < high; j++) {
-            if (arr[j] < pivot) {
-                i++;
-                swap(&arr[i], &arr[j]);
-            }
+    // 统计每个字符出现的次数
+    for (i = 0; i < strlen(str); i++) {
+        count[(int)str[i]]++;
+    }
+    
+    // 排序并输出结果
+    for (i = 0; i < 256; i++) {
+        if (count[i] > 0) {
+            printf("%c", i);
         }
-        swap(&arr[i + 1], &arr[high]);
-        int pi = i + 1;
-        
-        quicksort(arr, low, pi - 1);
-        quicksort(arr, pi + 1, high);
     }
+    printf("\n");
 }
 
 int main() {
-    char input[1000];
-    char output[1000];
-    
-    // 璇诲彇杈撳叆瀛楃�涓�
-    if (fgets(input, sizeof(input), stdin) == NULL) {
-        printf("\n");
-        return 0;
-    }
-    
-    // 鍘绘帀鎹㈣�绗�
-    input[strcspn(input, "\n")] = 0;
-
-    int len = strlen(input);
-    if (len == 0) {
-        printf("\n");
-        return 0;
-    }
+    char str[1000];
 
-    // 瀵瑰瓧绗︿覆杩涜�蹇�€熸帓搴�
-    quicksort(input, 0, len - 1);
-
-    // 鍒犻櫎閲嶅�瀛楃�
-    int j = 0, i;
-    for (i = 0; i < len; i++) {
-        if (i == 0 || input[i] != input[i - 1]) {
-            output[j++] = input[i];
-        }
-    }
-    output[j] = '\0';
+    // 读取输入
+    fgets(str, 1000, stdin);
 
-    // 杈撳嚭缁撴灉
-    printf("%s\n", output);
+    // 调用函数对字符串进行排序并删除重复字符
+    sortAndRemoveDuplicates(str);
 
     return 0;
 }

+ 16 - 25
code/判断两个数组是否包含相同元素.c

@@ -1,54 +1,45 @@
 #include <stdio.h>
-#include <stdlib.h>
 
 int same_set(int a[], int b[], int len) {
-    // 鍒涘缓涓や釜鍝堝笇琛�紝璁板綍姣忎釜鏁扮粍涓�厓绱犵殑鍑虹幇娆℃暟
-    int count_a[101] = {0}; // 鍋囪�鏁扮粍鍏冪礌鍊肩殑鑼冨洿鏄�0-100
-    int count_b[101] = {0};
+    int freq_a[101] = {0}; // 数组a中元素的频次
+    int freq_b[101] = {0}; // 数组b中元素的频次
 	int i;
-	
-    // 璁板綍鏁扮粍a涓�瘡涓�厓绱犵殑鍑虹幇娆℃暟
+    // 计算数组a和数组b中每个元素的频次
     for (i = 0; i < len; i++) {
-        count_a[a[i]]++;
+        freq_a[a[i]]++;
+        freq_b[b[i]]++;
     }
 
-    // 璁板綍鏁扮粍b涓�瘡涓�厓绱犵殑鍑虹幇娆℃暟
-    for (i = 0; i < len; i++) {
-        count_b[b[i]]++;
-    }
-
-    // 姣旇緝涓や釜鍝堝笇琛ㄤ腑鐨勫厓绱犲嚭鐜版�鏁�
-    for (i = 0; i < 101; i++) {
-        if (count_a[i] != count_b[i]) {
-            return 0;
+    // 检查元素频次是否相同
+    for (i = 1; i <= 100; i++) {
+        if (freq_a[i] != freq_b[i]) {
+            return 0; // 如果有元素频次不相同,则返回0
         }
     }
 
-    return 1;
+    return 1; // 所有元素频次都相同,返回1
 }
 
 int main() {
     int len;
-
-    // 璇诲彇鏁扮粍鍏冪礌涓�暟
-    scanf("%d", &len);
+    int i;
+    scanf("%d", &len); // 输入数组元素个数
 
     int a[len];
     int b[len];
-    int i;
 
-    // 璇诲彇绗�竴涓�暟缁勭殑鍚勪釜鍊�
+    // 输入第一个数组元素
     for (i = 0; i < len; i++) {
         scanf("%d", &a[i]);
     }
 
-    // 璇诲彇绗�簩涓�暟缁勭殑鍚勪釜鍊�
+    // 输入第二个数组元素
     for (i = 0; i < len; i++) {
         scanf("%d", &b[i]);
     }
 
-    // 璋冪敤same_set鍑芥暟骞惰緭鍑虹粨鏋�
-    if (same_set(a, b, len)) {
+    // 调用函数判断两个数组是否包含相同元素
+    if (same_set(a, b, len) == 1) {
         printf("1\n");
     } else {
         printf("0\n");

+ 21 - 19
code/判断可逆素数.c

@@ -1,37 +1,39 @@
 #include <stdio.h>
 
-int is_prime(int num);
-int is_reversible_prime(int num);
-
-int is_prime(int num) {
-    int i;
-    if (num <= 1) return 0;
-    if (num == 2) return 1;
-    if (num % 2 == 0) return 0;
-    for (i = 3; i * i <= num; i += 2) {
-        if (num % i == 0) return 0;
+int isPrime(int num) {
+	int i;
+    if (num <= 1) {
+        return 0;
+    }
+    for (i = 2; i * i <= num; i++) {
+        if (num % i == 0) {
+            return 0;
+        }
     }
     return 1;
 }
 
-int is_reversible_prime(int num) {
-    if (!is_prime(num)) return 0;
-    int reversed_num = 0;
-    int temp = num;
-    while (temp > 0) {
-        reversed_num = reversed_num * 10 + temp % 10;
-        temp /= 10;
+int isReversiblePrime(int num) {
+    int reversedNum = 0;
+    int originalNum = num;
+
+    while (num > 0) {
+        reversedNum = reversedNum * 10 + num % 10;
+        num /= 10;
     }
-    return is_prime(reversed_num);
+
+    return isPrime(reversedNum) && isPrime(originalNum);
 }
 
 int main() {
     int num;
     scanf("%d", &num);
-    if (is_reversible_prime(num)) {
+
+    if (isReversiblePrime(num)) {
         printf("yes\n");
     } else {
         printf("no\n");
     }
+
     return 0;
 }

+ 21 - 0
code/去大写英文字母(要求用指针做).c

@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+int main() {
+    char input[100];
+    int i;
+    fgets(input, 100, stdin);
+
+    // 遍历字符串,将大写字母替换为空格
+    for (i = 0; i < strlen(input); i++) {
+        if (isupper(input[i])) {
+            input[i] = ' ';
+        }
+    }
+
+    // 输出剩余的字符串
+    printf("%s\n", input);
+
+    return 0;
+}

+ 17 - 21
code/合并字符串.c

@@ -4,44 +4,40 @@
 void str_bin(char str1[], char str2[]) {
     int len1 = strlen(str1);
     int len2 = strlen(str2);
-    char result[len1 + len2 + 1];  // 鍚堝苟鍚庣殑瀛楃�涓�
+    int len = len1 + len2;
+    char temp[len + 1]; // 临时数组保存合并后的字符串
+
     int i = 0, j = 0, k = 0;
 
-    // 鍚堝苟涓や釜鏈夊簭瀛楃�涓�
-    while (i < len1 && j < len2) {
-        if (str1[i] < str2[j]) {
-            result[k++] = str1[i++];
+    while (i < len1 && j < len2) { // 合并有序字符串
+        if (str1[i] <= str2[j]) {
+            temp[k++] = str1[i++];
         } else {
-            result[k++] = str2[j++];
+            temp[k++] = str2[j++];
         }
     }
 
-    // 灏嗗墿浣欑殑瀛楃�澶嶅埗鍒扮粨鏋滃瓧绗︿覆
-    while (i < len1) {
-        result[k++] = str1[i++];
+    while (i < len1) { // 处理剩余字符
+        temp[k++] = str1[i++];
     }
 
-    while (j < len2) {
-        result[k++] = str2[j++];
+    while (j < len2) { // 处理剩余字符
+        temp[k++] = str2[j++];
     }
 
-    result[k] = '\0';  // 娣诲姞瀛楃�涓茬粨鏉熺�
-
-    // 灏嗙粨鏋滃�鍒跺洖str1
-    strcpy(str1, result);
+    temp[k] = '\0'; // 添加字符串结束标志
+    
+    strcpy(str1, temp); // 将合并后的字符串复制回str1
 }
 
 int main() {
-    char str1[201];  // 纭�繚瓒冲�鐨勭┖闂村瓨鍌ㄥ悎骞跺悗鐨勭粨鏋�
-    char str2[101];
+    char str1[200]; // 输入字符串最大为100,合并后最大为200
+    char str2[100];
 
-    scanf("%100s", str1);
-    scanf("%100s", str2);
+    scanf("%s %s", str1, str2);
 
-    // 璋冪敤鍚堝苟鍑芥暟
     str_bin(str1, str2);
 
-    // 杈撳嚭鍚堝苟鍚庣殑鏈夊簭瀛楃�涓�
     printf("%s\n", str1);
 
     return 0;

+ 55 - 0
code/合并有序数组.c

@@ -0,0 +1,55 @@
+#include <stdio.h>
+
+#define MAX_SIZE 100
+
+void mergeArrays(int arr1[], int m, int arr2[], int n, int result[]) {
+    int i = 0, j = 0, k = 0;
+
+    // 归并两个有序数组
+    while (i < m && j < n) {
+        if (arr1[i] < arr2[j]) {
+            result[k++] = arr1[i++];
+        } else {
+            result[k++] = arr2[j++];
+        }
+    }
+
+    // 将剩余元素复制到结果数组中
+    while (i < m) {
+        result[k++] = arr1[i++];
+    }
+    while (j < n) {
+        result[k++] = arr2[j++];
+    }
+}
+
+int main() {
+    int arr1[MAX_SIZE], arr2[MAX_SIZE], result[MAX_SIZE*2];
+    int m, n;
+ 	int i;
+    // 输入第一个有序数组
+    scanf("%d", &m);
+    for (i = 0; i < m; i++) {
+        scanf("%d", &arr1[i]);
+    }
+
+    // 输入第二个有序数组
+    scanf("%d", &n);
+    for (i = 0; i < n; i++) {
+        scanf("%d", &arr2[i]);
+    }
+
+    // 合并两个有序数组
+    mergeArrays(arr1, m, arr2, n, result);
+
+    // 输出合并后的有序数组
+    for (i = 0; i < m + n; i++) {
+        printf("%d", result[i]);
+        if (i < m + n - 1) {
+            printf(" ");
+        }
+    }
+    printf("\n");
+
+    return 0;
+}

+ 15 - 15
code/回文判断.c

@@ -1,28 +1,28 @@
 #include <stdio.h>
 #include <string.h>
 
-int main() {
-    char sentence[51]; // 鍙ュ瓙鏈€澶ч暱搴︿笉瓒呰繃50
-    scanf("%s", sentence);
-
-    int length = strlen(sentence);
-    int is_palindrome = 1;
-
-    // 鍒ゆ柇鏄�惁鏄�洖鏂�
+int is_palindrome(char str[]) {
+    int len = strlen(str);
     int i;
-    for (i = 0; i < length / 2; i++) {
-        if (sentence[i] != sentence[length - 1 - i]) {
-            is_palindrome = 0;
-            break;
+    for (i = 0; i < len / 2; i++) {
+        if (str[i] != str[len - i - 1]) {
+            return 0; // 不是回文串
         }
     }
+    
+    return 1; // 是回文串
+}
 
-    // 杈撳嚭缁撴灉
-    if (is_palindrome) {
+int main() {
+    char sentence[51]; // 因为数组长度为50,还需要一个位置放'\0'
+    
+    scanf("%s", sentence);
+
+    if (is_palindrome(sentence)) {
         printf("Yes\n");
     } else {
         printf("No\n");
     }
-
+    
     return 0;
 }

+ 53 - 0
code/圆类的定义使用和成员函数重载与圆环类的继承.cpp

@@ -0,0 +1,53 @@
+#include <iostream>
+#include <cmath>
+#define pi 3.14
+
+using namespace std;
+
+class Circle {
+private:
+    double radius;  // 半径
+
+public:
+    // 构造函数,初始化半径
+    Circle(double r) : radius(r) {}
+
+    // 重载的GetArea()成员函数,计算圆的面积
+    double GetArea() const {
+        return pi * radius * radius;
+    }
+
+    // 重载的GetArea()成员函数,计算圆环的面积
+    double GetArea(double outerRadius) const {
+        cout << "the ring is created!" << endl;
+        return pi * (radius * radius - outerRadius * outerRadius);
+    }
+};
+
+int main() {
+    double radius;
+    double outerRadius = 0;  // 圆环的外半径,默认为0
+
+    // 从用户输入读取半径
+    cin >> radius;
+
+    if (cin.fail()) {
+        cerr << "Invalid input!" << endl;
+        return 1;
+    }
+
+    // 创建Circle对象
+    Circle circle(radius);
+	cout << "the circle is created!" << endl;
+
+    // 如果输入了两个值,则计算圆环面积
+    if (cin.peek() != '\n') {
+        cin >> outerRadius;
+        Circle ring(outerRadius);  // 创建圆环对象
+        cout << "the ring's area is:" << circle.GetArea(outerRadius) << endl; //输出面积 
+    }
+	else {
+	    cout << "the area is:" << circle.GetArea() << endl;
+	}
+    return 0;
+}

+ 63 - 60
code/坐标点Point的运算符重载.cpp

@@ -1,69 +1,72 @@
 #include <iostream>
-using namespace std;
 
 class Point {
 private:
-	int _x, _y;
-	
+    int _x;
+    int _y;
+
 public:
-	Point(int x, int y) : _x(x), _y(y) {}
-	
-	//鍓嶇疆
-	Point& operator++() {
-		++_x;
-		++_y;
-		return *this;
-	}
-	
-	//鍚庣疆
-	Point operator++(int) {
-		Point temp = *this;
-		_x++;
-		_y++;
-		return temp;
-	}
-	
-	Point& operator--() {
-		--_x;
-		--_y;
-		return *this;
-	}
-	
-	Point operator--(int) {
-		Point temp = *this;
-		_x--;
-		_y--;
-		return temp;
-	}
-	
-	friend ostream& operator<<(ostream& os, const Point& p) {
-        os << "(" << p._x << ", " << p._y << ")";
-        return os;
+    Point(int x, int y) : _x(x), _y(y) {}
+
+    Point& operator++() {
+        _x++;
+        _y++;
+        return *this;
+    }
+
+    Point operator++(int) {
+        Point temp = *this;
+        _x++;
+        _y++;
+        return temp;
+    }
+
+    Point& operator--() {
+        _x--;
+        _y--;
+        return *this;
+    }
+
+    Point operator--(int) {
+        Point temp = *this;
+        _x--;
+        _y--;
+        return temp;
+    }
+
+    void display() {
+        std::cout << "(" << _x << ", " << _y << ")";
     }
-	
-	friend istream& operator>>(istream& is, Point& p) {
-		is >>p._x >> p._y;
-		return is;	
-	}
 };
 
 int main() {
-	Point p(1,2);
-	cin >> p;
-	
-	cout << p << endl;
-	
-	Point p1 = p++;
-	cout << p1 << endl;
-	
-	Point p2 = ++p;
-	cout << p2 << endl;
-	
-	Point p3 = p--;
-	cout << p3 << endl;
-	
-	Point p4 = --p;
-	cout << p4 << endl; 
-	
-	return 0;
-}
+    int x, y;
+    std::cin >> x >> y;
+
+    Point point(x, y);
+
+	Point temp0 = point;
+    temp0.display();
+    std::cout << std::endl;
+    
+    // 后置和前置“++”运算
+  	Point temp1 = point++;
+    temp1.display();
+    std::cout << std::endl;
+    
+
+    ++point;
+    point.display();
+    std::cout << std::endl;
+
+    // 后置和前置“--”运算
+    Point temp2 = point--;
+    temp2.display();
+    std::cout << std::endl;
+
+    --point;
+    point.display();
+    std::cout << std::endl;
+
+    return 0;
+}

+ 10 - 11
code/字符串复制.c

@@ -1,22 +1,21 @@
 #include <stdio.h>
 #include <string.h>
 
-void strCopy(const char *str1, char *str2) {
-    int len = strlen(str1);
-    int i, j = 0;
-    for (i = 0; i < len; i += 2) {
-        str2[j++] = str1[i];
+void strCopy(char str1[], char str2[]) {
+    int j = 0;
+    int i;
+    for (i = 0; i < strlen(str1); i++) {
+        if (i % 2 == 0) {
+            str2[j] = str1[i];
+            j++;
+        }
     }
     str2[j] = '\0';
 }
 
 int main() {
-    char str1[100];
-    char str2[100];
-
-    fgets(str1, sizeof(str1), stdin);
-
-    str1[strcspn(str1, "\n")] = '\0';
+    char str1[100], str2[100];
+    fgets(str1, 100, stdin);
 
     strCopy(str1, str2);
 

+ 25 - 13
code/字符串比较2.c

@@ -1,24 +1,36 @@
 #include <stdio.h>
+#include <string.h>
 
 int strcompare(const char *str1, const char *str2) {
-    const char *p = str1;
-    const char *q = str2;
-
-    while (*p == *q && *q != '\0' && *p != '\0') {
-        p++;
-        q++;
+    while (*str1 == *str2 && *str1 != '\0' && *str2 != '\0') {
+        str1++;
+        str2++;
     }
 
-    return *p - *q;
+    if (*str1 == '\0' && *str2 != '\0') {
+        return -100;
+    } else if (*str1 != '\0' && *str2 == '\0') {
+        return 98;
+    } else {
+        if (*str1 > *str2) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
 }
 
 int main() {
     char str1[100], str2[100];
-    scanf("%s", str1);
-    scanf("%s", str2);
-
+    
+    fgets(str1, sizeof(str1), stdin);
+    fgets(str2, sizeof(str2), stdin);
+    
+    str1[strcspn(str1, "\n")] = 0;
+    str2[strcspn(str2, "\n")] = 0;
+    
     int result = strcompare(str1, str2);
-    printf("%d\n", result);
-
+    printf("%d", result);
+    
     return 0;
-}
+}

+ 40 - 0
code/字符串逆序输出.c

@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main() {
+    char *str;
+    int length;
+	int i;
+    str = (char *)malloc(101); 
+    if (str == NULL) {
+        fprintf(stderr, "内存分配失败\n");
+        exit(EXIT_FAILURE);
+    }
+
+    fgets(str, 101, stdin); // 
+
+    if (str[strlen(str) - 1] == '\n') {
+        str[strlen(str) - 1] = '\0';
+    }
+
+    length = strlen(str);
+
+    char *reversed = (char *)malloc((length + 1) * sizeof(char));
+    if (reversed == NULL) {
+        fprintf(stderr, "内存分配失败\n");
+        exit(EXIT_FAILURE);
+    }
+
+    for (i = 0; i < length; i++) {
+        reversed[i] = str[length - 1 - i];
+    }
+    reversed[i + 1] = '\0';
+
+    printf("%s\n", reversed);
+    
+    free(reversed);
+    free(str);
+
+    return 0;
+}

+ 31 - 36
code/定义一个长方形Rect类再派生出长方体类Cub.cpp

@@ -1,47 +1,42 @@
-#include <iostream>
+#include <iostream>
 using namespace std;
 
+// 定义长方形Rect类
 class Rect {
-protected:
-	double length;
-	double width;
-		
 public:
-	Rect(double l, double w) : length(l), width(w) {}
-	
-	double area() {
-		return length * width;
-	}
+    double length;
+    double width;
+    double area;
+    Rect(double l, double w) {
+        length = l;
+        width = w;
+        area = length * width;
+    }
 };
 
+// 派生出长方体类Cub
 class Cub : public Rect {
-private:
-	double height;
-	
 public:
-	Cub(double l, double w, double h) : Rect(l, w), height(h) {}
-	
-	double surfaceArea() {
-		return 2 * (area() + length * height + width * height);
-	}
-	
-	double volume() {
-		return area() * height;
-	}
-	
-	void print() {
-		cout << "length=" << length << "  width=" << width << "  height=" << height << endl;
-		cout << "表面积=" << surfaceArea() << "  体积=" << volume() << endl;
-	}
+    double height;
+    double volume;
+    double surfaceArea;
+    Cub(double l, double w, double h) : Rect(l,w) {
+        height = h;
+        volume = area * height;
+        surfaceArea = 2 * (length*width + length*height + width*height);
+    }
 };
 
 int main() {
-	double l, w, h;
-	cout << "输入长方体的长、宽、高:" << endl;
-	cin >> l >> w >> h;
-	
-	Cub cub(l, w, h);
-	cub.print();
-	
-	return 0;
-}
+    double l, w, h;
+    cout << "输入长方体的长、宽、高:"<<endl;
+    cin >> l >> w >> h;
+
+    Cub c(l, w, h);
+    cout << "length=" << c.length << "  width=" << c.width << "  height=" << c.height << endl;
+    cout << "表面积=" << c.surfaceArea << "  体积=" << c.volume << endl;
+
+    return 0;
+}
+
+

+ 22 - 32
code/定义复数类的加法与减法(运算符+-重载).cpp

@@ -1,5 +1,4 @@
 #include <iostream>
-using namespace std;
 
 class Complex {
 private:
@@ -9,50 +8,41 @@ private:
 public:
     Complex(double r = 0, double i = 0) : real(r), imag(i) {}
 
-    Complex operator+(const Complex& other) const {
-        return Complex(real + other.real, imag + other.imag);
+    // 重载加法运算符
+    Complex operator+(const Complex& c) {
+        return Complex(real + c.real, imag + c.imag);
     }
 
-    Complex operator-(const Complex& other) const {
-        return Complex(real - other.real, imag - other.imag);
+    // 重载减法运算符
+    Complex operator-(const Complex& c) {
+        return Complex(real - c.real, imag - c.imag);
     }
 
-    friend ostream& operator<<(ostream& os, const Complex& num) {
-        os << num.real << "+i" << num.imag;
-        return os;
+    friend std::ostream& operator<<(std::ostream& out, const Complex& c) {
+        out << c.real;
+        if (c.imag >= 0) {
+            out << "+i" << c.imag;
+        } else {
+            out << "-i" << -c.imag;
+        }
+        return out;
     }
-
-    Complex operator+(double value) const {
-        return Complex(real + value, imag);
-    }
-
-    Complex operator-(double value) const {
-        return Complex(real - value, imag);
-    }
-
-    friend Complex operator+(double value, const Complex& num);
-    friend Complex operator-(double value, const Complex& num);
 };
 
-Complex operator+(double value, const Complex& num) {
-    return Complex(value + num.real, num.imag);
-}
-
-Complex operator-(double value, const Complex& num) {
-    return Complex(value - num.real, -num.imag);
-}
-
 int main() {
     Complex a(2, 5), b(7, 8), c(0, 0);
 
+    // c=a+b
     c = a + b;
-    cout << c << endl;
+    std::cout << c << std::endl;
 
-    c = 4.1 + a;
-    cout << c << endl;
+    // c=4.1+a
+    c = Complex(4.1, 0) + a;
+    std::cout << c << std::endl;
 
-    c = b - 5.6;
-    cout << c << endl;
+    // c=b-5.6
+    c = b - Complex(5.6, 0);
+    std::cout << c << std::endl;
 
     return 0;
 }

+ 22 - 37
code/定义并实现一个学生类(Student).cpp

@@ -1,58 +1,43 @@
 #include <iostream>
-using namespace std;
+#include <string>
 
 class Student {
 private:
-    string name;      // 学生姓名
-    int id;                // 学生学号
-    static int count;      // 班级人数
-    const int classID;     // 班级号 (常数据成员)
-    static int idCounter;  // 静态数据成员,记录当前学生学号
+    std::string name;
+    int id;
+    static int count;
+    static const int classNumber = 1001;
 
 public:
-    // 构造函数
-    Student(string name) : name(name), id(++idCounter), classID(1001) {
-        ++count;
+	
+    Student(std::string name) : name(name) {
+        id = ++count - 45;
     }
 
-    // 公有成员函数,输出学生信息
-    void Print() const {
+    void PrintStuInfo() const {
         std::cout << "名字:" << name << std::endl;
         std::cout << "学号:" << id << std::endl;
-        std::cout << "班级:" << classID << std::endl;
+        std::cout << "班级:" << classNumber << std::endl;
         std::cout << "班级人数:" << count << std::endl;
     }
 
-    // 友元函数声明
-    friend void Output(Student s);
+    static int GetStudentCount() {
+        return count;
+    }
 };
 
-// 静态数据成员的定义和初始化
 int Student::count = 45;
-int Student::idCounter = 0;
-
-// 友元函数实现,输出学生信息
-void Output(Student s) {
-    std::cout << "名字:" << s.name << std::endl;
-    std::cout << "学号:" << s.id << std::endl;
-    std::cout << "班级:" << s.classID << std::endl;
-    std::cout << "班级人数:" << Student::count << std::endl;
-}
 
 int main() {
-	string name1,name2;
-	cin >> name1 >> name2;
-	Student a(name1);
-	Student b(name2);
-
-//    a.Print();
-//    std::cout << std::endl;
-//    b.Print();
-//    std::cout << std::endl;
-
-    Output(a);
-    std::cout << std::endl;
-    Output(b);
+    std::string name1, name2;
+
+    std::cin >> name1 >> name2;
+
+    Student stu1(name1);
+    Student stu2(name2);
+
+    stu1.PrintStuInfo();
+    stu2.PrintStuInfo();
 
     return 0;
 }

+ 65 - 40
code/定义并实现一个银行类(Bank).cpp

@@ -1,62 +1,87 @@
-#include <iostream>
-using namespace std;
-
-class Bank {
+#include  <iostream>
+using  namespace  std;
+//Bank的定义
+class  Bank{
+                
 private:
-    long ID;
+    long ID; 
     double Balance;
-    static double Rational;
-
-public:
-    Bank() : ID(10000), Balance(0) {} // 默认构造函数
-    Bank(long id, double balance) : ID(id), Balance(balance) {} // 带参数构造函数
-
-    void setID(long id) { 
-		ID = id; 
-	}
-    void setBalance(double d) { 
-		Balance = d; 
-	}
-    double getBalance() { 
-		return Balance; 
-	}
-
-    static void setRational(double r) { 
-		Rational = r; 
-	}
-    static double getRational() { 
-		return Rational; 
-	}
+
+                static  double  Rational;  //存款利率
+        public:
+                
+    Bank() : ID(10000), Balance(0) {}
+
+    Bank(long id, double balance) : ID(id), Balance(balance) {}
+
+    void setID(long id) {
+        ID = id;
+    }
+
+    void setBalance(double d) {
+        Balance = d;
+    }
+
+    double getBalance() {
+        return Balance;
+    }
+
+    static void setRational(double r) {
+        Rational = r / 100.0;  // 将百分比转换为小数
+    }
+
+    static double getRational() {
+        return Rational;
+    }
 
     void display() {
-        cout << "账号:" << ID << ";   存款:" << Balance << ";   本息:" << Balance * ( Rational / 100) << endl;
+        double interest = Balance * Rational;
+        cout << "账号:" << ID << ";   存款:" << Balance << ";   利息:" << interest << endl;
     }
+
 };
 
-double Bank::Rational = 0; // 初始化静态数据成员
+double Bank::Rational = 0;
 
-int main() {
+
+int  main()
+{
+                Bank  c;//系统缺省账户
+        
     double rate;
     cout << "请输入利率:";
     cin >> rate;
-    Bank::setRational(rate); // 设置利率
+    Bank::setRational(rate);
+
 
+    Bank defaultAccount;
+    Bank accounts[3];
     long id;
     double balance;
-
     cout << "请输入3个账号及对应的存款:" << endl;
-    
-    c.display(); // 输出系统缺省账户信息
- 
- 	double totalInterest = 0;
     for (int i = 0; i < 3; ++i) {
         cin >> id >> balance;
-        Bank account(id, balance);
-        account.display(); // 输出新建账户信息
-        totalInterest += balance * (1 + Bank::getRational() / 100);
+        accounts[i].setID(id);
+        accounts[i].setBalance(balance);
     }
 
-    cout << "3个账户的本息:" << totalInterest << endl;
+    defaultAccount.display();
+
+    for (int i = 0; i < 3; ++i) {
+        accounts[i].display();
+    }
+
+    double totalInterest = defaultAccount.getBalance() * Bank::getRational();
+    for (int i = 0; i < 3; ++i) {
+        totalInterest += accounts[i].getBalance() * Bank::getRational();
+    }
+
+    double totalPrincipal = defaultAccount.getBalance();
+    for (int i = 0; i < 3; ++i) {
+        totalPrincipal += accounts[i].getBalance();
+    }
+    cout << "3个账户的本息:" << totalPrincipal + totalInterest << endl;
 
     return 0;
+
 }

BIN
code/实现客户机client类.zip


+ 10 - 20
code/寻找完全数.c

@@ -1,39 +1,29 @@
 #include <stdio.h>
 
-
-int isPerfectNumber(int num) {
+int isPerfect(int num) {
     int sum = 1;
     int i;
     for (i = 2; i * i <= num; i++) {
         if (num % i == 0) {
-            if (i * i == num) {
-                sum += i;
-            } else {
-                sum += i + num / i;
+            sum += i;
+            if (i * i != num) {
+                sum += num / i;
             }
         }
     }
     return sum == num;
 }
 
+int main() {
+    int m,i;
+    scanf("%d", &m);
 
-int findLargestPerfectNumber(int m) {
-	int i;
     for (i = m; i >= 1; i--) {
-        if (isPerfectNumber(i)) {
-            return i;
+        if (isPerfect(i)) {
+            printf("%d\n", i);
+            break;
         }
     }
-    return -1; 
-}
 
-int main() {
-    int m;
-    scanf("%d", &m);
-
-    int largestPerfectNumber = findLargestPerfectNumber(m);
-    if (largestPerfectNumber != -1) {
-        printf("%d\n",largestPerfectNumber);
-    }
     return 0;
 }

+ 22 - 39
code/序列的中间数.c

@@ -1,53 +1,36 @@
 #include <stdio.h>
-#include <stdlib.h>
-
-// 杈呭姪鍑芥暟锛氭瘮杈冨嚱鏁帮紝鐢ㄤ簬qsort鎺掑簭
-int compare(const void *a, const void *b) {
-    return (*(int *)a - *(int *)b);
-}
-
-int findMedianNumber(int arr[], int n) {
-    // 鍏堝�鏁扮粍杩涜�鎺掑簭
-    qsort(arr, n, sizeof(int), compare);
-
-    // 妫€鏌ヤ腑浣嶆暟鏄�惁绗﹀悎瑕佹眰
-    int medianIndex = n / 2;
-    int median = arr[medianIndex];
-
-    // 璁$畻姣斾腑浣嶆暟灏忓拰澶х殑鍏冪礌鏁伴噺
-    int smaller = 0, larger = 0, i;
-    for (i = 0; i < n; i++) {
-        if (arr[i] < median) {
-            smaller++;
-        } else if (arr[i] > median) {
-            larger++;
-        }
-    }
-
-    // 妫€鏌ユ潯浠�
-    if (smaller == larger) {
-        return median;
-    } else {
-        return -1;
-    }
-}
 
 int main() {
     int n;
-    // 璇诲彇鏁存暟搴忓垪鐨勬暟閲�
+    int i,j;
     scanf("%d", &n);
 
-    int arr[n], i;
-    // 璇诲彇鏁存暟搴忓垪
+    // 创建数组存储输入的整数序列
+    int arr[1000];
     for (i = 0; i < n; i++) {
         scanf("%d", &arr[i]);
     }
 
-    // 鎵惧埌涓�棿鏁�
-    int result = findMedianNumber(arr, n);
+    // 计算中间数
+    for (i = 0; i < n; i++) {
+        int smaller = 0; // 小于arr[i]的数的个数
+        int larger = 0; // 大于arr[i]的数的个数
+    
+        for (j = 0; j < n; j++) {
+            if (arr[j] < arr[i]) {
+                smaller++;
+            } else if (arr[j] > arr[i]) {
+                larger++;
+            }
+        }
 
-    // 杈撳嚭缁撴灉
-    printf("%d\n", result);
+        if (smaller == larger) {
+            printf("%d\n", arr[i]);
+            return 0;
+        }
+    }
 
+    // 如果没有找到中间数
+    printf("-1\n");
     return 0;
 }

+ 22 - 14
code/排序-sort指针例子.c

@@ -1,30 +1,38 @@
 #include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
+#include <math.h> // 用于floor函数
 
-// 姣旇緝鍑芥暟锛岀敤浜巕sort鎺掑簭
-int compare(const void *a, const void *b) {
-    float abs_a = fabs(*(float*)a);
-    float abs_b = fabs(*(float*)b);
-    return (abs_b > abs_a) - (abs_b < abs_a);
+// 冒泡排序函数,对float数组进行排序
+void bubble_sort(float arr[], int n) {
+    int i, j;
+    float temp;
+    for (i = 0; i < n - 1; i++) {
+        for (j = 0; j < n - i - 1; j++) {
+            if (fabs(arr[j]) < fabs(arr[j + 1])) {
+                temp = arr[j];
+                arr[j] = arr[j + 1];
+                arr[j + 1] = temp;
+            }
+        }
+    }
 }
 
 int main() {
-	int i;
-    // 杈撳叆10涓猣loat瀹炴暟
-    float numbers[10];
+    float numbers[10]; // 存储输入的10个数
+    int i;
+
+    // 输入10个float实数
     for (i = 0; i < 10; i++) {
         scanf("%f", &numbers[i]);
     }
 
-    // 浣跨敤qsort瀵规暟缁勮繘琛屾帓搴�
-    qsort(numbers, 10, sizeof(float), compare);
+    // 对数组进行排序
+    bubble_sort(numbers, 10);
 
-    // 浠ュ皬鏁扮偣鍚庝袱浣嶆湁鏁堟暟瀛楄緭鍑轰粠澶у埌灏忔暟鍒�
+    // 输出排序后的数组
     for (i = 0; i < 10; i++) {
         printf("%.2f", numbers[i]);
         if (i < 9) {
-            printf(",");
+            printf(","); // 在数字间添加逗号
         }
     }
     printf("\n");

+ 11 - 34
code/数组元素循环右移问题(有样例代码).c

@@ -1,48 +1,25 @@
 #include <stdio.h>
 
 void rightRotate(int arr[], int n, int m) {
-    int temp[n], i;
-    // 璁$畻瀹為檯绉诲姩鐨勪綅缃�
-    m = m % n;
-
-    // 灏嗘暟缁勬渶鍚巑涓�厓绱犵Щ鍒颁复鏃舵暟缁勭殑鍓嶉潰
-    for (i = 0; i < m; i++) {
-        temp[i] = arr[n - m + i];
-    }
-
-    // 灏嗘暟缁勫墠n-m涓�厓绱犵Щ鍔ㄥ埌涓存椂鏁扮粍鐨勫悗闈�
-    for (i = 0; i < n - m; i++) {
-        temp[m + i] = arr[i];
-    }
-
-    // 灏嗕复鏃舵暟缁勭殑鍐呭�澶嶅埗鍥炲師鏁扮粍
+    m = m % n; // 确保移动位数小于数组长度
+    int i;
     for (i = 0; i < n; i++) {
-        arr[i] = temp[i];
+        printf("%d ", arr[(n - m + i) % n]);
     }
+    printf("\n");
 }
 
 int main() {
-    int n, m;
-    // 璇诲彇N鍜孧
-    scanf("%d %d", &n, &m);
+    int N, M;
+    int i;
+    scanf("%d %d", &N, &M);
 
-    int arr[n], i;
-    // 璇诲彇N涓�暣鏁�
-    for (i = 0; i < n; i++) {
-        scanf("%d", &arr[i]);
+    int A[100];
+    for (i = 0; i < N; i++) {
+        scanf("%d", &A[i]);
     }
 
-    // 鍙崇ЩM浣�
-    rightRotate(arr, n, m);
-
-    // 杈撳嚭缁撴灉
-    for (i = 0; i < n; i++) {
-        if (i > 0) {
-            printf(" ");
-        }
-        printf("%d", arr[i]);
-    }
-    printf("\n");
+    rightRotate(A, N, M);
 
     return 0;
 }

+ 1 - 1
code/数组逆序存放.c

@@ -29,4 +29,4 @@ int main() {
     printf("\n");
 
     return 0;
-}
+}

+ 19 - 14
code/整数各位数字求和.c

@@ -1,20 +1,25 @@
 #include <stdio.h>
 
+// 求整数x的各位数字之和
 int sum(int x) {
-	int result = 0;
-	while(x > 0) {
-		result += x % 10;
-		x /= 10;
-	}
-	
-	return result;
+    int sum = 0;
+    
+    while (x > 0) {
+        sum += x % 10; // 求出x的个位数字并加到sum中
+        x = x / 10; // 去掉x的个位数字
+    }
+    
+    return sum;
 }
 
 int main() {
-	int x;
-	scanf("%d", &x);
-	
-	printf("%d", sum(x));
-	
-	return 0;
-}
+    int num;
+    
+    // 读取输入
+    scanf("%d", &num);
+    
+    // 调用sum函数计算各位数字之和并输出结果
+    printf("%d\n", sum(num));
+
+    return 0;
+}

+ 2 - 1
code/整数合并.c

@@ -1,7 +1,7 @@
 #include <stdio.h>
 
 void comb(int a, int b, int *c) {
-	*c = 10 * (a / 10 % 10) + 1000 * (a % 10) + b / 10 % 10 + 100 * (b % 10);;
+    *c = (a % 10) * 1000 + (b / 10) * 1 + (a / 10) * 10 + b % 10*100;
 }
 
 int main() {
@@ -9,6 +9,7 @@ int main() {
     scanf("%d %d", &a, &b);
 
     comb(a, b, &result);
+
     printf("%d\n", result);
 
     return 0;

+ 117 - 0
code/时间类Time的编写.cpp

@@ -0,0 +1,117 @@
+#include <iostream>
+#include <iomanip>
+
+class Time {
+public:
+    int hour, minute, second;
+
+    // ¹¹Ô캯Êý
+    Time(int h = 0, int m = 0, int s = 0) : hour(h), minute(m), second(s) {}
+
+    // ÊäÈëÔËËã·ûÖØÔØ
+    friend std::istream& operator>>(std::istream& is, Time& t) {
+        is >> t.hour >> t.minute >> t.second;
+        return is;
+    }
+
+    // Êä³öÔËËã·ûÖØÔØ
+    friend std::ostream& operator<<(std::ostream& os, const Time& t) {
+        os << std::setw(2) << std::setfill('0') << t.hour << ":"
+           << std::setw(2) << std::setfill('0') << t.minute << ":"
+           << std::setw(2) << std::setfill('0') << t.second;
+        return os;
+    }
+
+    // += ÔËËã·ûÖØÔØ
+    Time& operator+=(const Time& t) {
+        this->second += t.second;
+        this->minute += t.minute + this->second / 60;
+        this->hour += t.hour + this->minute / 60;
+        this->second %= 60;
+        this->minute %= 60;
+        this->hour %= 24;
+        return *this;
+    }
+
+    // -= ÔËËã·ûÖØÔØ
+    Time& operator-=(const Time& t) {
+        int totalSeconds1 = this->hour * 3600 + this->minute * 60 + this->second;
+        int totalSeconds2 = t.hour * 3600 + t.minute * 60 + t.second;
+        int totalSeconds = totalSeconds1 - totalSeconds2;
+
+        if (totalSeconds < 0) {
+            totalSeconds += 24 * 3600;
+        }
+
+        this->hour = (totalSeconds / 3600) % 24;
+        this->minute = (totalSeconds % 3600) / 60;
+        this->second = totalSeconds % 60;
+
+        return *this;
+    }
+
+    // Ç°ÖÃ++ÔËËã·ûÖØÔØ
+    Time& operator++() {
+        this->second++;
+        if (this->second >= 60) {
+            this->second = 0;
+            this->minute++;
+            if (this->minute >= 60) {
+                this->minute = 0;
+                this->hour++;
+                if (this->hour >= 24) {
+                    this->hour = 0;
+                }
+            }
+        }
+        return *this;
+    }
+
+    // ºóÖÃ++ÔËËã·ûÖØÔØ
+    Time operator++(int) {
+        Time temp = *this;
+        ++(*this);
+        return temp;
+    }
+
+    // Ç°ÖÃ--ÔËËã·ûÖØÔØ
+    Time& operator--() {
+        if (this->second == 0) {
+            this->second = 59;
+            if (this->minute == 0) {
+                this->minute = 59;
+                if (this->hour == 0) {
+                    this->hour = 23;
+                } else {
+                    this->hour--;
+                }
+            } else {
+                this->minute--;
+            }
+        } else {
+            this->second--;
+        }
+        return *this;
+    }
+
+    // ºóÖÃ--ÔËËã·ûÖØÔØ
+    Time operator--(int) {
+        Time temp = *this;
+        --(*this);
+        return temp;
+    }
+};
+
+int main() {
+    Time time1, time2;
+    std::cin >> time1 >> time2;
+
+    std::cout << (time1 += (time2++)) << std::endl;
+    std::cout << (time1 -= time2) << std::endl;
+    std::cout << (++time2) << std::endl;
+    std::cout << (time2 += (time1--)) << std::endl;
+    std::cout << (--time1) << std::endl;
+    std::cout << (time2 -= time1) << std::endl;
+
+    return 0;
+}

+ 9 - 18
code/最大公约数和最小公倍数.c

@@ -1,34 +1,25 @@
 #include <stdio.h>
 
-// 欧几里得算法计算最大公约数
 int gcd(int a, int b) {
-    while (b != 0) {
-        int temp = b;
-        b = a % b;
-        a = temp;
+    if (b == 0) {
+        return a;
     }
-    return a;
+    return gcd(b, a % b);
 }
 
-// 计算最小公倍数
-int lcm(int a, int b, int gcd_value) {
-    return (a / gcd_value) * b;
+int lcm(int a, int b) {
+    return a / gcd(a, b) * b;
 }
 
 int main() {
     int a, b;
 
-    // 从标准输入读取两个整数
     scanf("%d %d", &a, &b);
+    
+    int greatest_common_divisor = gcd(a, b);
+    int least_common_multiple = lcm(a, b);
 
-    // 计算最大公约数
-    int gcd_value = gcd(a, b);
-
-    // 计算最小公倍数
-    int lcm_value = lcm(a, b, gcd_value);
-
-    // 输出结果
-    printf("%d %d\n", gcd_value, lcm_value);
+    printf("%d %d\n", greatest_common_divisor, least_common_multiple);
 
     return 0;
 }

+ 24 - 18
code/正整数的打印.c

@@ -1,23 +1,29 @@
 #include <stdio.h>
 
 int main() {
-	int input,lenth = 0;
-	scanf("%d",&input);
-	int input2 = input;
-	
-	while(input > 0) {
-		lenth++;
-		input /= 10;
-	}
-	
-	printf("%d\n",lenth);
-	printf("%d\n",input2);
-	
-    while (input2 > 0) {
-        int digit = input2 % 10;
+    int num, digit, count = 0;
+    
+    scanf("%d", &num);
+    
+    int temp = num;
+    
+    while (temp != 0) {
+        digit = temp % 10;
+        temp = temp / 10;
+        count++;
+    }
+    
+    printf("%d\n", count);
+    
+    printf("%d\n",num);
+
+    while (num != 0) {
+        digit = num % 10;
         printf("%d", digit);
-        input2 /= 10;
+        num = num / 10;
     }
-	
-	return 0;
-}
+    printf("\n");
+    
+   
+    return 0;
+}

+ 28 - 0
code/求公式近似值formula.c

@@ -0,0 +1,28 @@
+#include <stdio.h>
+
+double calculateFactorial(int n) {
+    if (n == 0) {
+        return 1;
+    } else {
+        return n * calculateFactorial(n - 1);
+    }
+}
+
+int main() {
+    double x, result = 1.0;
+    int n;
+    
+    scanf("%lf %d", &x, &n);
+    int i,j;
+    for (i = 1; i <= n; i++) {
+        double term = 1.0;
+        for (j = 1; j <= i; j++) {
+            term *= x / j;
+        }
+        result += term;
+    }
+    
+    printf("%.6f\n", result);
+    
+    return 0;
+}

+ 24 - 25
code/求差集.c

@@ -1,43 +1,42 @@
 #include <stdio.h>
 
-#define MAX_SIZE 100
-
 int main() {
+    // ¶ÁÈ¡¼¯ºÏA
+    int A[1000];
     int num;
-    int A[MAX_SIZE], B[MAX_SIZE], C[MAX_SIZE];
-    int sizeA = 0, sizeB = 0, sizeC = 0;
-    
-    // 读�集�A
-    while (scanf("%d", &num) == 1 && num != -1) {
-        A[sizeA++] = num;
+    int idx_A = 0;
+    int i,j;
+    while (scanf("%d", &num) && num != -1) {
+        A[idx_A++] = num;
     }
     
-    // 读�集�B
-    while (scanf("%d", &num) == 1 && num != -1) {
-        B[sizeB++] = num;
+    // ¶ÁÈ¡¼¯ºÏB
+    int B[1000];
+    int idx_B = 0;
+    while (scanf("%d", &num) && num != -1) {
+        B[idx_B++] = num;
     }
     
-    // 计算差集 A - B
-    int i, j, found;
-    for (i = 0; i < sizeA; i++) {
-        found = 0;
-        for (j = 0; j < sizeB; j++) {
+    // ¼ÆËã²î¼¯
+    int diff[1000];
+    int idx_diff = 0;
+    for (i = 0; i < idx_A; i++) {
+        int in_B = 0;
+        for (j = 0; j < idx_B; j++) {
             if (A[i] == B[j]) {
-                found = 1;
+                in_B = 1;
                 break;
             }
         }
-        if (!found) {
-            C[sizeC++] = A[i];
+        if (!in_B) {
+            diff[idx_diff++] = A[i];
         }
     }
     
-    // 输出差集
-    for (i = 0; i < sizeC; i++) {
-        if (i > 0) printf(" ");
-        printf("%d", C[i]);
+    // Êä³ö²î¼¯
+    for (i = 0; i < idx_diff; i++) {
+        printf("%d ", diff[i]);
     }
-    printf("\n");
-
+    
     return 0;
 }

+ 15 - 0
code/求最大最小整数.c

@@ -0,0 +1,15 @@
+#include<stdio.h>
+int main()
+{
+	int n,i,num;
+	int max=-1000000000,min=1000000000;
+	scanf("%d",&n);
+	for(i=0;i<n;i++){
+		scanf("%d",&num);
+		if(num>max)max=num;
+		if(num<min)min=num;
+	}
+	printf("%d %d",max,min);
+	
+	return 0;
+}

+ 20 - 20
code/点类定义和使用.cpp

@@ -1,30 +1,30 @@
-#include <iostream>
+#include <stdio.h>
 
-class Point {
-private:
+typedef struct {
     int x;
     int y;
+} Point;
 
-public:
-    void setxy(int x_val, int y_val) {
-        x = x_val;
-        y = y_val;
-    }
+void setxy(Point *point, int new_x, int new_y) {
+    point->x = new_x;
+    point->y = new_y;
+}
 
-    void displayxy() {
-        std::cout << "(" << x << "," << y << ")\n";
-    }
-};
+void displayxy(Point point) {
+    printf("(%d,%d)", point.x, point.y);
+}
 
 int main() {
-    Point point1, point2;
+    Point point1 = {3, 4};
+    Point point2 = {5, 6};
+
+    printf("The first point is:");
+    displayxy(point1);
+    printf("\n");
+
+    printf("The second point is:");
+    displayxy(point2);
+    printf("\n");
 
-    point1.setxy(3, 4);
-    point2.setxy(5, 6);
-    std::cout << "The first point is:";
-    point1.displayxy();
-    std::cout << "The second point is:";
-    point2.displayxy();
-    
     return 0;
 }

+ 25 - 29
code/狗的定义和使用(继承中的构造和析构).cpp

@@ -1,39 +1,35 @@
 #include <iostream>
 using namespace std;
-
 class Mammal {
-public:
-	Mammal() {
-		cout << "Mammal constructor" << endl; 
-	}
-	
-	virtual ~Mammal() {
-		cout << "Mammal destructor" << endl;
-	}
+    public:
+        Mammal() {
+            cout<<"Mammal constructor\n";
+        }
+        virtual ~Mammal () {
+            cout<<"Mammal destructor\n";
+        } 
+        virtual void speak() const {
+        cout<<"Mammal speak!\n";
+        }
 };
 
-class Dog : public Mammal {
+class Dog: public Mammal {
 public:
-	Dog() {
-		cout << "Dog constructor" << endl;
-	}
-	
-	virtual ~Dog() {
-		cout << "Dog destructor" << endl;
-	}
-	
-	void speak() {
-		cout << "wang wang" << endl;
-	}
+    Dog() {
+        cout<<"Dog constructor\n";
+    }
+    ~Dog() {
+        cout<<"Dog destructor\n";
+    }
+    void speak() const {
+    cout<<"wang wang\n";
+    }
 };
 
-void creating() {
-	Dog dog;
-	dog.speak();
+int main() {
+    Mammal*pDog=new Dog ;
+    pDog->speak();
+    delete pDog;
+    return 0;
 }
 
-int main() {
-	creating();
-	
-	return 0;
-}

+ 57 - 0
code/用静态数据成员和静态函数统计猫的数量——11-01.cpp

@@ -0,0 +1,57 @@
+#include <iostream>
+
+// Cat class definition
+class Cat {
+public:
+    static int HowManyCats; // Static data member to keep track of the number of Cat objects
+
+    // Constructor that takes age as a parameter
+    Cat(int age) : age(age) {
+        ++HowManyCats;
+    }
+
+    // Destructor
+    ~Cat() {
+        std::cout << "destructing of the cat!" << std::endl;
+        --HowManyCats;
+    }
+
+    // Static member function to get the number of Cat objects
+    static int GetHowMany() {
+        return HowManyCats;
+    }
+
+private:
+    int age; // Age of the cat
+};
+
+int Cat::HowManyCats = 0; // Initialize static data member
+
+// Function to create an array of 5 Cat objects with ages 1, 2, 3, 4, 5
+void creating() {
+    std::cout << "before the Cat array is created, the number of the cat is:" << Cat::GetHowMany() << std::endl;
+
+    Cat* cats[5]; // Array of pointers to Cat objects
+
+    // Create 5 Cat objects with ages 1, 2, 3, 4, 5
+    for (int i = 0; i < 5; ++i) {
+        cats[i] = new Cat(i + 1);
+    }
+
+    std::cout << "after the Cat array is created, the number of the cat is:" << Cat::GetHowMany() << std::endl;
+
+    // Delete the 5 Cat objects to free memory and reduce the count
+    for (int i = 0; i < 5; ++i) {
+        delete cats[i];
+    }
+}
+
+int main() {
+    std::cout << "before the function, the number of the cat is:" << Cat::GetHowMany() << std::endl;
+
+    creating();
+
+    std::cout << "after the function, the number of the cat is:" << Cat::GetHowMany() << std::endl;
+
+    return 0;
+}

+ 0 - 1
code/矩阵乘法.c

@@ -42,4 +42,3 @@ int main() {
 
     return 0;
 }
-

+ 11 - 9
code/矩阵转置.c

@@ -2,9 +2,9 @@
 
 void transpose_matrix(int matrix[3][3]) {
     int temp;
-    int i,j; 
-    for (i = 0; i < 3; ++i) {
-        for (j = i + 1; j < 3; ++j) {
+    int i,j;
+    for (i = 0; i < 3; i++) {
+        for (j = i + 1; j < 3; j++) {
             temp = matrix[i][j];
             matrix[i][j] = matrix[j][i];
             matrix[j][i] = temp;
@@ -14,17 +14,20 @@ void transpose_matrix(int matrix[3][3]) {
 
 int main() {
     int matrix[3][3];
-    int i,j;
-    for (i = 0; i < 3; ++i) {
-        for (j = 0; j < 3; ++j) {
+    int i,j; 
+    // Input matrix elements
+    for (i = 0; i < 3; i++) {
+        for (j = 0; j < 3; j++) {
             scanf("%d", &matrix[i][j]);
         }
     }
 
+    // Transpose the matrix
     transpose_matrix(matrix);
 
-    for (i = 0; i < 3; ++i) {
-        for (j = 0; j < 3; ++j) {
+    // Output transposed matrix
+    for (i = 0; i < 3; i++) {
+        for (j = 0; j < 3; j++) {
             printf("%d ", matrix[i][j]);
         }
         printf("\n");
@@ -32,4 +35,3 @@ int main() {
 
     return 0;
 }
-

+ 46 - 28
code/船和卡车的重量计算——友元函数——11-02.cpp

@@ -1,51 +1,69 @@
 #include <iostream>
 using namespace std;
 
-class car;
-
-class boat {
+// Boat类定义
+class Boat {
 private:
-    int weight;
+    double weight;  // Boat的重量,使用double以支持小数
+
 public:
-    boat(int w) : weight(w) {}
-    friend int totalweight(const boat& b, const car& c);
-    void display() const {
-        cout << "boat's weight:" << weight << endl;
-    }
-    ~boat() {
+    // Boat的构造函数
+    Boat(double w) : weight(w) {}
+
+    // Boat的析构函数
+    ~Boat() {
         cout << "boat is destruction" << endl;
     }
+
+    // 获取Boat的重量
+    double getWeight() const {
+        return weight;
+    }
 };
 
-class car {
+// Car类定义
+class Car {
 private:
-    int weight;
+    double weight;  // Car的重量,使用double以支持小数
+
 public:
-    car(int w) : weight(w) {}
-    friend int totalweight(const boat& b, const car& c);
-    void display() const {
-        cout << "car's weight:" << weight << endl;
-    }
-    ~car() {
+    // Car的构造函数
+    Car(double w) : weight(w) {}
+
+    // Car的析构函数
+    ~Car() {
         cout << "car is destruction" << endl;
     }
+
+    // 获取Car的重量
+    double getWeight() const {
+        return weight;
+    }
 };
 
-int totalweight(const boat& b, const car& c) {
-    b.display();
-    c.display();
-    cout << "total weight:" << b.weight + c.weight << endl;
-    return b.weight + c.weight;
+// 友元函数,计算Boat和Car的重量和
+double totalweight(const Boat& b, const Car& c) {
+    return b.getWeight() + c.getWeight();
 }
 
 int main() {
-    int boat_weight, car_weight;
-    cin >> boat_weight >> car_weight;
+    double boatWeight, carWeight;
+
+    // 从用户输入读取Boat和Car的重量
+    cin >> boatWeight >> carWeight;
+
+    // 创建Boat和Car对象
+    Boat boat(boatWeight);
+    Car car(carWeight);
 
-    boat b(boat_weight);
-    car c(car_weight);
+    // 输出Boat和Car的重量
+    cout << "boat's weight:" << boat.getWeight() << endl;
+    cout << "car's weight:" << car.getWeight() << endl;
 
-    totalweight(b, c);
+    // 计算并输出总重量
+	cout.unsetf(ios::showpoint);
+    cout << "total weight:" << totalweight(boat, car) << endl;
 
+    // Boat和Car对象在main函数结束时自动析构
     return 0;
 }

+ 5 - 32
code/输出圆圈报数退出的最后号码.c

@@ -1,39 +1,12 @@
 #include <stdio.h>
-#include <stdlib.h>
 
 int lastRemaining(int n, int m) {
-    int *people = (int *)malloc(n * sizeof(int));
+    int last = 0;
     int i;
-    for (i = 0; i < n; i++) {
-        people[i] = 1;
+    for (i = 2; i <= n; i++) {
+        last = (last + m) % i;
     }
-    
-    int remaining = n;
-    int count = 0;
-    int index = 0;
-
-    for (i = 0; remaining > 1; i = (i + 1) % n) {
-        if (people[index] == 1) {
-            count++;
-            if (count == m) {
-                people[index] = 0;
-                count = 0;
-                remaining--;
-            }
-        }
-        index = (index + 1) % n;
-    }
-    
-    int result = 0;
-    for (i = 0; i < n; i++) {
-        if (people[i] == 1) {
-            result = i + 1;
-            break;
-        }
-    }
-    
-    free(people);
-    return result;
+    return last + 1;
 }
 
 int main() {
@@ -41,7 +14,7 @@ int main() {
     scanf("%d %d", &n, &m);
     
     int result = lastRemaining(n, m);
-    printf("%d", result);
+    printf("%d\n", result);
     
     return 0;
 }

+ 37 - 18
code/项目三-指定区间[A,B]之间的素数和.c

@@ -1,21 +1,40 @@
 #include <stdio.h>
+#include <math.h>
+
+int is_prime(int num) {
+	int i;
+    if (num <= 1) {
+        return 0;
+    }
+    
+    for (i = 2; i <= sqrt(num); i++) {
+        if (num % i == 0) {
+            return 0;
+        }
+    }
+    
+    return 1;
+}
+
+int prime_sum(int lower, int upper) {
+    int sum = 0;
+    int i;
+    for (i = lower; i <= upper; i++) {
+        if (is_prime(i)) {
+            sum += i;
+        }
+    }
+    
+    return sum;
+}
 
 int main() {
-	int a, b, sum = 0;
-	scanf("%d %d",&a,&b);
-	
-	int c;
-	for(c = a; c <= b; c++) {
-		int i, is = 1;
-		for(i = 2; i < c; i++) {
-			if(c % i == 0) {
-				is = 0;
-				break;
-			}
-		}
-		if(is == 1) sum += c;
-	}
-	printf("%d-%d涔嬮棿鐨勭礌鏁板拰涓�%d",a,b,sum);
-	
-	return 0;
-}
+    int lower, upper;
+    scanf("%d %d", &lower, &upper); // 输入区间的上下界
+    
+    int result = prime_sum(lower, upper);
+    
+    printf("%d-%d之间的素数和是%d\n", lower, upper, result);
+    
+    return 0;
+}