主頁 >  其他 > 練習C編程這一篇就夠了

練習C編程這一篇就夠了

2020-09-29 02:17:13 其他

目錄

    • 第一章、遞回呼叫(13道)
    • 第二類、特殊數字(24道)
    • 第三類、多維陣列(08道)
    • 第四類、字符處理(14道)
    • 第五類、數學問題(15道)
    • 第六類、排序演算法(04道)
    • 第七類、回圈問題(17道)
    • 第八類、進制轉換(05道)
    • 第九類、實際應用(27道)
    • 第十類、圖形輸出(09道)


第一章、遞回呼叫(13道)

1.漢諾塔:請輸入盤子數,輸出盤子移動的操作步驟,

#include <stdio.h>

void move(char from, char to) {
    printf("%c to %c\n", from, to);
}

void hanoi(int n, char a, char b, char c) {
    if (n == 1)
        move(a, c);
    else {
        hanoi(n - 1, a, c, b);
        move(a, c);
        hanoi(n - 1, b, a, c);
    }
}

void main() {
    int n;
    scanf("%d", &n);
    hanoi(n, 'A', 'B', 'C');
}

2.爬樓梯:樹老師爬樓梯,他可以每次走1級或者2級,輸入樓梯的級數,求不同的走法數,

#include <stdio.h>

int stair(int n) {
    if (n == 1) return 1;
    if (n == 2) return 2;
    return stair(n - 1) + stair(n - 2);
}

void main() {
    int n;
    scanf("%d", &n);
    printf("%d", stair(n));
}

3.爬樓梯:樹老師爬樓梯,他可以每次走1級、2級或者3級,輸入樓梯的級數,求不同的走法數,

#include <stdio.h>

int stair(int n) {
    if (n == 1) return 1;
    if (n == 2) return 2;
    if (n == 3) return 4;
    return stair(n - 1) + stair(n - 2) + stair(n - 3);
}

void main() {
    int n;
    scanf("%d", &n);
    printf("%d", stair(n));
}

4.斐波那契數列:請輸入項數,輸出具體數列,

#include <stdio.h>

int fibonacci(int n) {
    if (n == 1 || n == 2)
        return 1;
    return fibonacci(n - 1) + fibonacci(n - 2);
}

void main() {
    int n, i;
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
        printf("%d,", fibonacci(i));
}

5.求階乘:請輸入整數n,求1!+2!+3!+4!+5!+6!+7!+…+n!的和,

#include <stdio.h>

int factorial(int n) {
    if (n == 1) return 1;
    return n * factorial(n - 1);
}

void main() {
    int n, i, sum = 0;
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
        sum += factorial(i);
    printf("sum=%d", sum);
}

6.取球問題:在n個球中,任意取m個(不放回),求有多少種不同取法,

#include <stdio.h>

int ball(int n, int m) {
    if (n < m)  return 0;
    if (n == m) return 1;
    if (m == 0) return 1;
    return ball(n - 1, m - 1) + ball(n - 1, m);
}

void main() {
    int n, m;
    scanf("%d%d", &n, &m);
    printf("%d", ball(n, m));
}

7.楊輝三角:輸入要列印的層數,列印楊輝三角,

#include <stdio.h>

int triangle(int m, int n) {
    if (m == 0 || n == 0 || m == n)
        return 1;
    return triangle(m - 1, n) + triangle(m - 1, n - 1);
}

void main() {
    int n, i, j;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        for (j = 0; j <= i; j++) {
            printf("%d ", triangle(i, j));
        }
        printf("\n");
    }
}

8.求年齡:有5個人坐在一起,問第5個人多少歲,他說比第4個人大2歲,問第4個人多少歲,他說比第3個人大2歲,問第3個人多少歲,他說比第2個人大2歲,問第2個人多少歲,他說比第1個人大2歲,最后問第1個人,他說是10歲,請問第5個人多大?

#include <stdio.h>

int age(int n) {
    if (n == 1) return 10;
    return age(n - 1) + 2;
}

void main() {
    printf("%d", age(5));
}

9.猴子吃桃問題:猴子第一天摘下若干個桃子,當即吃了一半,還不癮,又多吃了一個,第二天早上又將剩下的桃子吃掉一半,又多吃了一個,以后每天早上都吃了前一天剩下的一半多一個,到第十天早上想再吃時,見只剩下一個桃子了,問最初有多少個桃子,

遞回:

#include <stdio.h>

int peach(int n) {
    if (n == 10) return 1;
    return (peach(n + 1) + 1) * 2;
}

void main() {
    printf("%d", peach(1));
}

回圈:

#include <stdio.h>

void main() {
    int i, s = 1;
    for (i = 9; i >= 1; i--) {
        s = (s + 1) * 2;
    }
    printf("%d", s);
}

10.猴子吃桃問題:猴子第一天摘下若干個桃子,當即吃了一半,還不癮,又多吃了一個,第二天早上又將剩下的桃子吃掉一半,又多吃了一個,以后每天早上都吃了前一天剩下的一半多一個,第十天同樣是吃了前一天的一半加一個,最后剩下一個桃子,問最初有多少個桃子,

遞回:

#include <stdio.h>

int peach(int n) {
    if (n == 11) return 1;
    return (peach(n + 1) + 1) * 2;
}

void main() {
    printf("%d", peach(1));
}

回圈:

#include <stdio.h>

void main() {
    int i, s = 1;
    for (i = 10; i >= 1; i--) {
        s = (s + 1) * 2;
    }
    printf("%d", s);
}

11.最大公約數:利用遞回演算法求兩個數的最大公約數,

#include <stdio.h>

/* 最大公約數 */
int gcd(int a, int b) {
    int t;
    if (a < b) {
        t = a;
        a = b;
        b = t;
    }
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

void main() {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("gcd=%d", gcd(a, b));
}

12.逆序輸出:輸入一個正整數,將該正整數逆序輸出,

#include <stdio.h>

void printDigit(int n) {
    printf("%d", n % 10);
    if (n > 10) {
        printDigit(n / 10);
    }
}

void main() {
    int n;
    scanf("%d", &n);
    printDigit(n);
}

13.逆序輸出:輸入一個字串,將該字串逆序輸出,

#include <stdio.h>

void printStr(char *str) {
    if (*str != '\0')
        printStr(str + 1);
    if (*str != '\0')
        printf("%c", *str);
}

void main() {
    char str[100];
    gets(str);
    printStr(str);
}

第二類、特殊數字(24道)

1.奇數:輸出1-1000之間所有的奇數,

#include <stdio.h>

void main() {
    int i;
    for (i = 1; i <= 1000; i++)
        if (i % 2 == 1)
            printf("%d,", i);
}

2.偶數:輸出1-1000之間所有的偶數,

#include <stdio.h>

void main() {
    int i;
    for (i = 1; i <= 1000; i++)
        if (i % 2 == 0)
            printf("%d,", i);
}

3.素數:輸出1-1000之間所有的素數,

#include <stdio.h>

void main() {
    int i, j;
    for (i = 1; i <= 1000; i++) {
        for (j = 2; j < i; j++)
            if (i % j == 0)
                break;
        if (i == j)
            printf("%d,", i);
    }
}

4.完數:輸出1-1000之間所有的完數,

#include <stdio.h>

void main() {
    int i, j, s;
    for (i = 1; i <= 1000; i++) {
        s = 0;
        for (j = 1; j < i; j++)
            if (i % j == 0)
                s += j;
        if (i == s)
            printf("%d,", i);
    }
}

5.回文數:輸出100-999之間所有的回文數,

#include <stdio.h>

void main() {
    int i, g, b;
    for (i = 100; i <= 999; i++) {
        g = i % 10;
        b = i / 100;
        if (g == b)
            printf("%d,", i);
    }
}

6.水仙花數:輸出100-999之間所有的水仙花數,

#include <stdio.h>

void main() {
    int i, g, s, b;
    for (i = 100; i <= 999; i++) {
        g = i % 10;
        s = i / 10 % 10;
        b = i / 100;
        if (g * g * g + s * s * s + b * b * b == i)
            printf("%d,", i);
    }
}

7.中位數:計算有限個數的資料的中位數的方法是:把所有的同類資料按照大小的順序排列,如果資料的個數是奇數,則中間那個資料就是這群資料的中位數;如果資料的個數是偶數,則中間那2個資料的算術平均值就是這群資料的中位數,現在給出n個正整數,求它們的中位數,

#include <stdio.h>

/* 冒泡排序 */
void sort(int a[], int n) {
    int i, j, t;
    for (i = 0; i < n - 1; i++) {
        for (j = 0; j < n - 1 - i; j++) {
            if (a[j] > a[j + 1]) {
                t = a[j];
                a[j] = a[j + 1];
                a[j + 1] = t;
            }
        }
    }
}

void main() {
    int a[100], n, i;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a, n);
    if (n % 2 == 1) {
        printf("%d", a[n / 2]);
    } else {
        printf("%.2f", (a[n / 2] + a[n / 2 - 1]) / 2.0);
    }
}

8.完全平方數:若一個數能表示成某個數的平方的形式,則稱這個數為完全平方數,

#include <stdio.h>
#include <math.h>

int ISquare(int n) {
    int m = (int) sqrt(n);
    if (m * m == n)
        return m;
    return 0;
}

void main() {
    int n, p;
    scanf("%d", &n);
    if (p = ISquare(n))
        printf("%d是完全平方數,%d=%d*%d\n", n, n, p, p);
    else
        printf("%d非完全平方數\n", n);
}

9.亂數:生成100個1(含1)-100(含100)之間的亂數,

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int getRand(int min, int max) {
    return rand() % (max - min + 1) + min;
}

void main() {
    int i;
    srand(time(NULL));
    for (i = 1; i <= 100; i++) {
        printf("%d\n", getRand(1, 100));
    }
}

10.求年份:輸出2000(含2000)-2020(含2020)之間所有的閏年年份,

#include <stdio.h>

void main() {
    int y;
    for (y = 2000; y <= 2020; y++)
        if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))
            printf("%d,", y);
}

11.求數字:求兩個整數的最大公約數及最小公倍數,

#include <stdio.h>

/* 最大公約數 */
int gcd(int a, int b) {
    int t;
    if (a < b) {
        t = a;
        a = b;
        b = t;
    }
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

/* 最小公倍數 */
int lcm(int a, int b, int c) {
    return a * b / c;
}

void main() {
    int x, y, a, b;
    scanf("%d%d", &a, &b);
    x = gcd(a, b);
    y = lcm(a, b, x);
    printf("gcd=%d,lcm=%d", x, y);
}

12.求數字:一個整數,它加上100后是一個完全平方數,它加上168又是一個完全平方數,請問該數是多少?

#include <stdio.h>
#include <math.h>

void main() {
    int i = 1, x, y;
    while (1) {
        x = (int) sqrt(i + 100);
        y = (int) sqrt(i + 168);
        if ((x * x == i + 100) && (y * y == i + 168)) {
            printf("%d", i);
            break;
        }
        i++;
    }
}

13.求數字:一個整數,它加上100后是一個完全平方數,再加上168又是一個完全平方數,請問該數是多少?

#include <stdio.h>
#include <math.h>

void main() {
    int i = 1, x, y;
    while (1) {
        x = (int) sqrt(i + 100);
        y = (int) sqrt(i + 100 + 168);
        if ((x * x == i + 100) && (y * y == i + 100 + 168)) {
            printf("%d", i);
            break;
        }
        i++;
    }
}

14.求數字:求所有的四位數中,原數的9倍與其逆序相等的數,

#include <stdio.h>

void main() {
    int i, a, b, c, d;
    for (i = 1000; i <= 9999; i++) {
        a = i % 10;
        b = i / 10 % 10;
        c = i / 100 % 10;
        d = i / 1000;
        if (9 * i == a * 1000 + b * 100 + c * 10 + d)
            printf("%d", i);
    }
}

15.求數字:輸出2000(含2000)-3000(含3000)之間所有十位數是m(0<=m<=9)且是n的倍數的數,

#include <stdio.h>

void main() {
    int m, n, i;
    scanf("%d %d", &m, &n);
    for (i = 2000; i <= 3000; i++)
        if (i / 10 % 10 == m && i % n == 0)
            printf("%d,", i);
}

16.求數字:輸入一個整數n,輸出100(含100)-999(含999)之間所有各位數字之和等于n的數,

#include <stdio.h>

void main() {
    int n, a, b, c, i;
    scanf("%d", &n);
    for (i = 100; i <= 999; i++) {
        a = i / 100;
        b = i / 10 % 10;
        c = i % 10;
        if (a + b + c == n)
            printf("%d,", i);
    }
}

17.求數字:求1(含1)-200(含200)中,能同時被2、5除余1的整數,

#include <stdio.h>

void main() {
    int i;
    for (i = 1; i <= 200; i++)
        if (i % 2 == 1 && i % 5 == 1)
            printf("%d,", i);
}

18.求數字:輸出100(含100)-999(含999)之間所有是7的倍數的回文數,

#include <stdio.h>

void main() {
    int i, a, c;
    for (i = 100; i <= 999; i++) {
        a = i / 100;
        c = i % 10;
        if (a == c && i % 7 == 0)
            printf("%d,", i);
    }
}

19.求數字:輸出100(含100)-200(含200)以內的十位數字為5,百位和個位的和是6的倍數的所有的數,

#include <stdio.h>

void main() {
    int i, a, b, c;
    for (i = 100; i <= 200; i++) {
        a = i / 100;
        b = i / 10 % 10;
        c = i % 10;
        if (b == 5 && (a + c) % 6 == 0)
            printf("%d,", i);
    }
}

20.求數字:輸出100(含100)-200(含200)以內的滿足以下條件的數,條件為:這個數與3的和是5的倍數,與3的差是6的倍數,輸出這樣的數,

#include <stdio.h>

void main() {
    int i;
    for (i = 100; i <= 200; i++)
        if ((i + 3) % 5 == 0 && (i - 3) % 6 == 0)
            printf("%d,", i);
}

21.求數字:找出乘積為399的兩個相鄰奇數,

#include <stdio.h>

void main() {
    int i = 1;
    while (i * (i + 2) != 399)
        i = i + 2;
    printf("%d,%d", i, i + 2);
}

22.求位數:輸入一個正整數,輸出它是幾位數?

#include <stdio.h>

void main() {
    int n, count = 1;
    scanf("%d", &n);
    while (n = n / 10) {
        count++;
    }
    printf("%d", count);
}

23.求數和:輸入一個正整數,求其各位之和,

#include <stdio.h>

void main() {
    int n, sum = 0;
    scanf("%d", &n);
    while (n > 0) {
        sum += n % 10;
        n = n / 10;
    }
    printf("%d", sum);
}

24.相反數:輸入一個正整數,輸出它的相反數,

#include <stdio.h>

void main() {
    int n, sum = 0;
    scanf("%d", &n);
    while (n > 0) {
        sum = sum * 10 + n % 10;
        n = n / 10;
    }
    printf("%d", sum);
}

第三類、多維陣列(08道)

1.上下對稱反轉

#include <stdio.h>

void main() {
    int arr[4][5] = {
            {1,  2,  3,  4,  5},
            {6,  7,  8,  9,  10},
            {11, 12, 13, 14, 15},
            {16, 17, 18, 19, 20},
    };
    int i, j, t;
    int rows = sizeof(arr) / sizeof(arr[0]);
    int cols = sizeof(arr[0]) / sizeof(arr[0][0]);

    for (i = 0; i < rows / 2; i++) {
        for (j = 0; j < cols; j++) {
            t = arr[rows - 1 - i][j];
            arr[rows - 1 - i][j] = arr[i][j];
            arr[i][j] = t;
        }
    }

    for (i = 0; i < rows; i++) {
        for (j = 0; j < cols; j++)
            printf("%-5d", arr[i][j]);
        printf("\n");
    }
}

2.左右對稱反轉

#include <stdio.h>

void main() {
    int arr[4][5] = {
            {1,  2,  3,  4,  5},
            {6,  7,  8,  9,  10},
            {11, 12, 13, 14, 15},
            {16, 17, 18, 19, 20},
    };
    int i, j, t;
    int rows = sizeof(arr) / sizeof(arr[0]);
    int cols = sizeof(arr[0]) / sizeof(arr[0][0]);

    for (i = 0; i < rows; i++) {
        for (j = 0; j < cols / 2; j++) {
            t = arr[i][cols - 1 - j];
            arr[i][cols - 1 - j] = arr[i][j];
            arr[i][j] = t;
        }
    }

    for (i = 0; i < rows; i++) {
        for (j = 0; j < cols; j++)
            printf("%-5d", arr[i][j]);
        printf("\n");
    }
}

3.上下左右反轉

#include <stdio.h>

void main() {
    int arr[4][5] = {
            {1,  2,  3,  4,  5},
            {6,  7,  8,  9,  10},
            {11, 12, 13, 14, 15},
            {16, 17, 18, 19, 20},
    };
    int i, j, t;
    int rows = sizeof(arr) / sizeof(arr[0]);
    int cols = sizeof(arr[0]) / sizeof(arr[0][0]);
    /* 上下對稱反轉 */
    for (i = 0; i < rows / 2; i++) {
        for (j = 0; j < cols; j++) {
            t = arr[rows - 1 - i][j];
            arr[rows - 1 - i][j] = arr[i][j];
            arr[i][j] = t;
        }
    }
    /* 左右對稱反轉 */
    for (i = 0; i < rows; i++) {
        for (j = 0; j < cols / 2; j++) {
            t = arr[i][cols - 1 - j];
            arr[i][cols - 1 - j] = arr[i][j];
            arr[i][j] = t;
        }
    }
    /* 二維陣列列印 */
    for (i = 0; i < rows; i++) {
        for (j = 0; j < cols; j++)
            printf("%-5d", arr[i][j]);
        printf("\n");
    }
}

4.判斷a[N][N]是否關于主對角線對稱(左斜),若對稱輸出1,否則輸出0,

#include <stdio.h>
#define N 5

void main() {
    int a[N][N], i, j, flag = 1;
    for (i = 0; i < N; i++)
        for (j = 0; j < N; j++)
            scanf("%d", &a[i][j]);
    for (i = 0; i < N; i++)
        for (j = 0; j < i; j++)
            if (a[i][j] != a[j][i]) {
                flag = 0;
                break;
            }
    if (flag == 1)
        printf("1");
    else
        printf("0");
}

5.判斷a[N][N]是否關于次對角線對稱(右斜),若對稱輸出1,否則輸出0,

#include <stdio.h>
#define N 5

void main() {
    int a[N][N], i, j, flag = 1;
    for (i = 0; i < N; i++)
        for (j = 0; j < N; j++)
            scanf("%d", &a[i][j]);
    for (i = 0; i < N; i++)
        for (j = 0; j < N - 1 - i; j++)
            if (a[i][j] != a[N - 1 - j][N - 1 - i]) {
                flag = 0;
                break;
            }
    if (flag == 1)
        printf("1");
    else
        printf("0");
}

6.分別求出N階方陣a中兩個對角線上元素之和,

#include <stdio.h>
#define N 5

void main() {
    int a[N][N], i, j, k = N, pr1 = 0, pr2 = 0;
    for (i = 0; i < N; i++)
        for (j = 0; j < N; j++)
            scanf("%d", &a[i][j]);
    for (i = 0; i < N; i++) {
        pr1 += a[i][i];
        k = k - 1;
        pr2 += a[i][k];
    }
    printf("pr1=%d\n", pr1);
    printf("pr2=%d\n", pr2);
}

7.N階方陣a進行轉置,輸出行列互換后的方陣a,

#include <stdio.h>
#define N 5

void main() {
    int a[N][N], i, j, t;
    for (i = 0; i < N; i++)
        for (j = 0; j < N; j++)
            scanf("%d", &a[i][j]);
    for (i = 0; i < N; i++)
        for (j = 0; j < i; j++) {
            t = a[i][j];
            a[i][j] = a[j][i];
            a[j][i] = t;
        }
    for (i = 0; i < N; i++) {
        for (j = 0; j < N; j++)
            printf("%-5d", a[i][j]);
        printf("\n");
    }
}

8.N階方陣a加上方陣a的轉置存放在方陣b中,輸出方陣b,

#include <stdio.h>
#define N 5

void main() {
    int a[N][N], b[N][N], i, j;
    for (i = 0; i < N; i++)
        for (j = 0; j < N; j++)
            scanf("%d", &a[i][j]);
    for (i = 0; i < N; i++)
        for (j = 0; j < N; j++)
            b[i][j] = a[i][j] + a[j][i];
    for (i = 0; i < N; i++) {
        for (j = 0; j < N; j++)
            printf("%d ", b[i][j]);
        printf("\n");
    }
}

第四類、字符處理(14道)

1.撰寫函式:int cmp(char *str1,char *str2),實作字串的比較,

#include <stdio.h>

int cmp(char *str1, char *str2) {
    while (*str1 == *str2 && *str1 != '\0') {
        str1++;
        str2++;
    }
    return *str1 - *str2;
}

void main() {
    char s1[100] = "ABCDEF1";
    char s2[100] = "ABCDEF0";
    printf("%d", cmp(s1, s2));
}

2.撰寫函式:void cpy(char *dest,char *src),實作字串的拷貝,

#include <stdio.h>

void cpy(char *dest, char *src) {
    while (*dest++ = *src++);
}

void main() {
    char s1[100] = "AABCD123ABCD123ABCDA";
    char s2[100] = "123";
    cpy(s1, s2);
    puts(s1);
}

3.撰寫函式:void cat(char *dest,char *src),實作字串的追加,

#include <stdio.h>

void cat(char *dest, char *src) {
    while (*dest++);
    dest--;
    while (*dest++ = *src++);
}

void main() {
    char s1[100] = "AABCD123ABCD123ABCDA";
    char s2[100] = "123";
    cat(s1, s2);
    puts(s1);
}

4.撰寫函式:void reverse(char *str),實作字串的反轉,

#include <stdio.h>

void reverse(char *str) {
    char *start = str, *end = str, t;
    while (*end++);
    end -= 2;
    while (start < end) {
        t = *start;
        *start++ = *end;
        *end-- = t;
    }
}

void main() {
    char str[100] = "123456789";
    reverse(str);
    puts(str);
}

5.撰寫函式:int len(char *str),判斷字串的長度,

#include <stdio.h>

int len(char *str) {
    char *p = str;
    while (*str++);
    return str - 1 - p;
}

void main() {
    printf("%d", len("AABCD123ABCD123ABCDA"));
}

6.撰寫函式:int strchc(char *str, char c),實作統計str字串中指定字符出現的個數,

#include <stdio.h>

int strchc(char *str, char c) {
    int count = 0;
    while (*str) {
        if (*str == c) {
            count++;
        }
        str++;
    }
    return count;
}

void main() {
    printf("%d", strchc("AABCD123ABCD123ABCDA", 'A'));
}

7.撰寫函式:int strstrc(char *str, char *substr),實作統計str字串中指定字串出現的個數,

#include <stdio.h>

int strstrc(char *str, char *substr) {
    int count = 0;
    char *pb, *ps;
    while (*str) {
        pb = str;
        ps = substr;
        while (*ps) {
            if (*pb == *ps) {
                pb++;
                ps++;
            } else {
                break;
            }
        }
        if (*ps == '\0') {
            count++;
        }
        str++;
    }
    return count;
}

void main() {
    printf("%d", strstrc("AABCD123ABCD123ABCDA", "ABCD"));
}

8.撰寫函式:void delch(char *str, char c),實作洗掉str字串中出現所有指定字符,

#include <stdio.h>

void delch(char *str, char c) {
    char *p = str;
    while (*str) {
        if (*str != c) {
            *p++ = *str;
        }
        str++;
    }
    *p = '\0';
}

void main() {
    char s1[100] = "AABCD123ABCD123ABCDA";
    char c = 'A';
    delch(s1, c);
    puts(s1);
}

9.撰寫函式:char *delstr(char *str, char *substr),實作洗掉str字串中出現所有指定字串,

#include <stdio.h>
#include <string.h>

char *delstr(char *str, char *substr) {
    char *pb = str, *q, *c;
    int n = strlen(substr);
    while (q = strstr(pb, substr)) {
        c = q + n;
        *q = '\0';
        pb = strcat(pb, c);
    }
    return pb;
}

void main() {
    char s1[100] = "AABCD123ABCD123ABCDA";
    char s2[100] = "ABCD";
    delstr(s1, s2);
    puts(s1);
}

10.撰寫函式:void repch(char *str, char subch, char repch),將str字串中出現的所有字符subch替換為repch,

#include <stdio.h>

void repch(char *str, char subch, char repch) {
    while (*str) {
        if (*str == subch) {
            *str = repch;
        }
        str++;
    }
}

void main() {
    char str[100] = "abcdefabcdefabcdef";
    repch(str, 'a', 'A');
    puts(str);
}

11.撰寫函式:void repstr(char *str, char *substr, char *repstr),將str字串中出現的所有子串substr替換為repstr,

#include <stdio.h>

void repstr(char *str, char *substr, char *repstr) {
    char *pb, *ps;
    while (*str) {
        pb = str;
        ps = substr;
        while (*ps) {
            if (*pb == *ps) {
                pb++;
                ps++;
            } else {
                break;
            }
        }
        if (*ps == '\0') {
            ps = repstr;
            while (*ps)
                *str++ = *ps++;
        } else {
            str++;
        }
    }
}

void main() {
    char str[100] = "abcdefabcdefabcdef";
    repstr(str, "abc", "XYZ");
    puts(str);
}

12.撰寫函式:char *strch(char *str, char c),如果指定字符是str字串的元素,回傳元素所在的首地址,否則,回傳NULL,

#include <stdio.h>

char *strch(char *str, char c) {
    while (*str) {
        if (*str == c) {
            return str;
        }
        str++;
    }
    return NULL;
}

void main() {
    char s1[100] = "AABCD123ABCD123ABCDA";
    char c = '1';
    printf("%s", strch(s1, c));
}

13.撰寫函式:char *strstr(char *str, char *substr),如果指定字串是str字串的元素,回傳元素所在的首地址,否則,回傳NULL,

#include <stdio.h>

char *strstr(char *str, char *substr) {
    char *pb, *ps;
    while (*str) {
        pb = str;
        ps = substr;
        while (*ps) {
            if (*pb == *ps) {
                pb++;
                ps++;
            } else {
                break;
            }
        }
        if (*ps == '\0') {
            return str;
        }
        str++;
    }
    return NULL;
}

void main() {
    char s1[100] = "AABCD123ABCD123ABCDA";
    char s2[100] = "123";
    printf("%s", strstr(s1, s2));
}

14.輸入多個字串,輸出其中最短的第一個字串,

#include <stdio.h>
#include <string.h>

void main() {
    char str[100] = {0}, min[100] = {0};
    while (1) {
        printf("Please enter a string:\n");
        gets(str);
        if (str[0] == '\0') {
            break;
        }
        if (strlen(str) >= strlen(min)) {
            strcpy(min, str);
        }
    }
    printf("min=%s\n", min);
}

第五類、數學問題(15道)

1.雞兔同籠:假設雞兔共30只,腳88只,問雞兔各有多少只?

#include <stdio.h>

void main() {
    int i, j;
    for (i = 0; i <= 30; i++) {
        j = 30 - i;
        if (2 * i + 4 * j == 88)
            printf("%d,%d", i, j);
    }
}

2.百錢百雞:100元錢買100只雞,公雞5塊錢一只,母雞3塊錢一只,小雞一塊錢3只,請輸出所有組合,

#include <stdio.h>

void main() {
    int a, b, c;
    for (a = 0; a <= 20; a++) {
        for (b = 0; b <= 33; b++) {
            c = 100 - a - b;
            if (a * 5 + b * 3 + c / 3 == 100 && c % 3 == 0)
                printf("%d,%d,%d\n", a, b, c);
        }
    }
}

3.斐波那契數列:請用回圈輸出斐波那契數列的前20項,

#include <stdio.h>

void main() {
    int i, a = 1, b = 1;
    for (i = 1; i <= 10; i++) {
        printf("%d,%d,", a, b);
        a = a + b;
        b = a + b;
    }
}

4.兔子數列(又稱斐波那契數列):有一對兔子,從出生后第3個月起每個月都生一對兔子,小兔子長到第三個月后每個月又生一對兔子,假如兔子都不死,問前10個月,每個月有兔子多少對?

#include <stdio.h>

int fibonacci(int n) {
    if (n == 1 || n == 2)
        return 1;
    return fibonacci(n - 1) + fibonacci(n - 2);
}

void main() {
    int i;
    for (i = 1; i <= 10; i++) {
        printf("the %d month has %d\n", i, fibonacci(i));
    }
}

5.兔子數列(又稱斐波那契數列):有一對兔子,從出生后第三個月起每個月都生一對兔子,小兔子長到第三個月后每個月又生一對兔子,假如兔子都不死,請問第一個月出生的一對兔子,至少需要繁衍到第幾個月時兔子總數才可以達到N對?

#include <stdio.h>

int fibonacci(int n) {
    if (n == 1 || n == 2)
        return 1;
    return fibonacci(n - 1) + fibonacci(n - 2);
}

void main() {
    int m = 1, n, s = 0;
    scanf("%d", &n);
    while ((s = fibonacci(m)) < n) {
        m++;
    }
    printf("到第%d個月,才有%d對兔子,已有%d對兔子\n", m, n, s);
}

6.數字組合:有1、2、3、4,四個數字,能組成多少個互不相同且無重復數字的三位數?

#include <stdio.h>

void main() {
    int a, b, c;
    for (a = 1; a < 5; a++)
        for (b = 1; b < 5; b++)
            for (c = 1; c < 5; c++)
                if ((a != b) && (a != c) && (b != c))
                    printf("%d,%d,%d\n", a, b, c);
}

7.字母組合:有A、B、C、D,四個字母,能組成多少個互不相同且無重復三位組合?

#include <stdio.h>

void main() {
    int a, b, c;
    for (a = 65; a < 69; a++)
        for (b = 65; b < 69; b++)
            for (c = 65; c < 69; c++)
                if ((a != b) && (a != c) && (b != c))
                    printf("%c,%c,%c\n", a, b, c);
}

8.比賽抽簽:兩個乒乓球隊進行比賽,各出三人,甲隊為a,b,c三人,乙隊為x,y,z三人,已抽簽決定比賽名單,有人向隊員打聽比賽的名單,a說他不和x比,c說他不和x,z比,請編程式找出三隊賽手的名單,

#include <stdio.h>

void main() {
    char a, b, c;
    for (a = 'x'; a <= 'z'; a++)
        for (b = 'x'; b <= 'z'; b++)
            for (c = 'x'; c <= 'z'; c++)
                if (a != b && a != c && b != c)
                    if (a != 'x' && c != 'x' && c != 'z')
                        printf("order as a--%c\tb--%c\tc--%c\n",
                               a, b, c);
}

9.韓信點兵:韓信有一隊兵,他想知道有多少人,便讓士兵排隊報數,按從1至5報數,最末一個士兵報的數為1;按從1至6報數,最末一個士兵報的數為5;按從1至7報數,最末一個士兵報的數為4;最后再按從1至11報數,最末一個士兵報的數為10,計算韓信至少有多少兵,

#include <stdio.h>

void main() {
  int x;
  for (x = 1;; x++) {
    if (x % 5 == 1 && x % 6 == 5 && x % 7 == 4 && x % 11 == 10) {
      printf("%d", x);
      break;
    }
  }
}

10.愛因斯坦:有一條長階梯,若每步跨2階,最后剩下1階;若每步跨3階,最后剩下2階;若每步跨5階,最后剩下4階;若每步跨6階,最后剩下5階;只有每步跨7階,最后才正好1階不剩,計算這條階梯共有多少階,

#include <stdio.h>

void main() {
    int x;
    for (x = 1;; x++) {
        if (x%2==1 && x%3==2 && x%5==4 && x%6==5 && x%7==0) {
            printf("%d", x);
            break;
        }
    }
}

11.哥德巴赫猜想:任何一個大于2的偶數總能表示為兩個素數之和,比如:24=5+19,其中5和19都是素數,請撰寫程式驗證,

#include <stdio.h>

int isPrime(long p) {
    long i;
    for (i = 2; i < p; i++)
        if (p % i == 0)
            return 0;
    return 1;
}

void main() {
    long n, p1, p2;
    scanf("%ld", &n);
    for (p1 = 3; p1 <= n / 2; p1 += 2) {
        p2 = n - p1;
        if (isPrime(p1) && isPrime(p2)) {
            printf("%ld=%ld+%ld\n", n, p1, p2);
            break;
        }
    }
}

12.分解質因數:每個合數(非質數)都可以寫成幾個質數相乘的形式,這幾個質數就叫做這個合數的質因數,比如,24可以被分解為2 2 2 3,請輸入一個合數,輸出它的質因數,

#include <stdio.h>

void main() {
    int n, i;
    scanf("%d", &n);
    while (n != 1) {
        for (i = 2; i <= n; i++) {
            if (n % i == 0) {
                printf("%d ", i);
                n = n / i;
                break;
            }
        }
    }
}

13.一元二次方程:求一元二次方程〖ax〗^2+bx+c=0的解(a、b、c為任意實數),

#include <stdio.h>
#include <math.h>

void main() {
    double a, b, c, disc, x1, x2, realpart, imagpart;
    scanf("%lf%lf%lf", &a, &b, &c);
    printf("The equation ");
    if (fabs(a) <= 1e-6)
        printf("is not a quadratic");
    else {
        disc = b * b - 4 * a * c;
        if (fabs(disc) <= 1e-6)
            printf("has two equal roots:%8.4f", -b / (2 * a));
        else if (disc > 1e-6) {
            x1 = (-b + sqrt(disc)) / (2 * a);
            x2 = (-b - sqrt(disc)) / (2 * a);
            printf("has two differ roots:%8.4f and %8.4f", x1, x2);
        } else {
            realpart = -b / (2 * a);
            imagpart = sqrt(-disc) / (2 * a);
            printf("has complex roots:\n");
            printf("%8.4f+%8.4fi\n", realpart, imagpart);
            printf("%8.4f-%8.4fi\n", realpart, imagpart);
        }
    }
}

14.三角形的周長和面積:給定平面上任意三個點的坐標(x1,y1)、(x2,y2)、(x3,y3),撰寫程式檢驗它們能否構成三角形,若這三個點不能構成三角形,則輸出“Impossible”;若可以,則輸出該三角形的周長和面積,

#include <stdio.h>
#include <math.h>

void main() {
    float x1, x2, x3, y1, y2, y3;
    float a, b, c, s, l, area;
    scanf("%f%f%f%f%f%f", &x1, &y1, &x2, &y2, &x3, &y3);
    a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    b = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
    c = sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
    if (a + b > c && a + c > b && b + c > a) {
        s = (a + b + c) / 2;
        area = sqrt(s * (s - a) * (s - b) * (s - c));
        l = a + b + c;
        printf("L = %.2f, A = %.2f\n", l, area);
    } else {
        printf("Impossible\n");
    }
}

15.圓的周長和面積:輸入圓的半徑,輸出圓的周長和面積,Π=3.14

#include <stdio.h>

void main() {
    float r, l, area;
    scanf("%f", &r);
    l = 2 * 3.14 * r;
    area = 3.14 * r * r;
    printf("L = %.2f, A = %.2f\n", l, area);
}

第六類、排序演算法(04道)

1.冒泡排序法,

#include <stdio.h>

void bubble_sort(int arr[], int len) {
    int i, j, t;
    for (i = 0; i < len - 1; i++) {
        for (j = 0; j < len - 1 - i; j++) {
            if (arr[j] > arr[j + 1]) {
                t = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = t;
            }
        }
    }
}

void main() {
    int arr[] = {11, 99, 22, 88, 33, 77, 44, 66, 55, 55}, i;
    bubble_sort(arr, 10);
    for (i = 0; i < 10; i++) {
        printf("%-4d", arr[i]);
    }
}

2.選擇排序法,

第一種:高效率,

#include <stdio.h>

void selction_sort(int arr[], int len) {
    int i, j, t, min;
    for (i = 0; i < len - 1; i++) {
        min = i;
        for (j = i + 1; j < len; j++) {
            if (arr[min] > arr[j])
                min = j;
        }
        if (min != i) {
            t = arr[min];
            arr[min] = arr[i];
            arr[i] = t;
        }
    }
}

void main() {
    int arr[] = {11, 99, 22, 88, 33, 77, 44, 66, 55, 55}, i;
    selction_sort(arr, 10);
    for (i = 0; i < 10; i++) {
        printf("%-4d", arr[i]);
    }
}

第二種:低效率,

#include <stdio.h>

void selction_sort(int arr[], int len) {
    int i, j, t;
    for (i = 0; i < len - 1; i++) {
        for (j = i + 1; j < len; j++) {
            if (arr[i] > arr[j]) {
                t = arr[i];
                arr[i] = arr[j];
                arr[j] = t;
            }
        }
    }
}

void main() {
    int arr[] = {11, 99, 22, 88, 33, 77, 44, 66, 55, 55}, i;
    selction_sort(arr, 10);
    for (i = 0; i < 10; i++) {
        printf("%-4d", arr[i]);
    }
}

3.插入排序法,

#include <stdio.h>

void insertion_sort(int arr[], int len) {
    int i, j, t;
    for (i = 0; i < len - 1; i++) {
        for (j = i + 1; j > 0; j--) {
            if (arr[j - 1] > arr[j]) {
                t = arr[j - 1];
                arr[j - 1] = arr[j];
                arr[j] = t;
            } else {
                break;
            }
        }
    }
}

void main() {
    int arr[] = {11, 99, 22, 88, 33, 77, 44, 66, 55, 55}, i;
    insertion_sort(arr, 10);
    for (i = 0; i < 10; i++) {
        printf("%-4d", arr[i]);
    }
}

4.字串排序,

#include <stdio.h>
#include <string.h>
#define N 4

void main() {
    int i, j;
    char s[N][100], t[100];
    for (i = 0; i < N; i++)
        gets(s[i]);
    for (i = 0; i < N - 1; i++)
        for (j = 0; j < N - 1 - i; j++)
            if (strcmp(s[j], s[j + 1]) > 0) {
                strcpy(t, s[j]);
                strcpy(s[j], s[j + 1]);
                strcpy(s[j + 1], t);
            }
    for (i = 0; i < N; i++)
        puts(s[i]);
}

第七類、回圈問題(17道)

1.求總和:1+2+3+4+5+…+100,

#include <stdio.h>

void main() {
    int i, sum = 0;
    for (i = 1; i <= 100; i++)
        sum += i;
    printf("%d", sum);
}

2.求總和:-1+2-3+4-5+…+100,

#include <stdio.h>

void main() {
    int i, sum = 0;
    for (i = 1; i <= 100; i++) {
        if (i % 2 == 1)
            sum -= i;
        else
            sum += i;
    }
    printf("%d", sum);
}

3.求總和:1-2+3-4+5-…-100,

#include <stdio.h>

void main() {
    int i, sum = 0;
    for (i = 1; i <= 100; i++) {
        if (i % 2 == 0)
            sum -= i;
        else
            sum += i;
    }
    printf("%d", sum);
}

4.求總和:11+22+33+44+55+66+77+88+99,

#include <stdio.h>

void main() {
    int i, sum = 0;
    for (i = 1; i <= 9; i++)
        sum += (i * 10 + i);
    printf("%d", sum);
}

5.求總和:s=a+aa+aaa+…+aaa(n個a),輸入a表示基數,輸入n表示項數,

#include <stdio.h>

void main() {
    int a, n, i, t = 0, sum = 0;
    scanf("%d%d", &a, &n);
    for (i = 1; i <= n; i++) {
        t = t * 10 + a;
        sum += t;
    }
    printf("%d", sum);
}

6.求總和:1-100以內所有奇數的和,

#include <stdio.h>

void main() {
    int i, sum = 0;
    for (i = 1; i <= 100; i += 2)
        sum += i;
    printf("%d", sum);
}

7.求總和:1-100以內所有偶數的和,

#include <stdio.h>

void main() {
    int i, sum = 0;
    for (i = 2; i <= 100; i += 2)
        sum += i;
    printf("%d", sum);
}

8.遞回求和:1!+2!+3!+4!+5!+6!+7!+8!+9!+10!,

#include <stdio.h>

void main() {
    int i, n = 1, sum = 0;
    for (i = 1; i <= 10; i++) {
        n *= i;
        sum += n;
    }
    printf("%d", sum);
}

9.斐波那契數列求和:1+1+2+3+5+8+…+6765,

#include <stdio.h>

void main() {
    int i, a = 1, b = 1, sum = 0;
    for (i = 1;; i++) {
        sum += (a + b);
        if (b == 6765)
            break;
        a = a + b;
        b = a + b;
    }
    printf("%d", sum);
}

10.分數求和:1-1/3+1/5-1/7+…-1/99+1/101,

#include <stdio.h>

void main() {
    int i, t = 1;
    float n, sum = 0;
    for (i = 1; i <= 101; i += 2) {
        n = (1.0 / i) * t;
        sum += n;
        t = -t;
    }
    printf("%.2f", sum);
}

11.求Π的值:根據以下公式求Π的近似值,要求累加到某項的絕對值小于1e-6時為止,

image-20200818104602569

#include <stdio.h>
#include <math.h>

void main() {
    double fz = 1, fm = 3, s = 1, i = 1;
    while (fabs(fz / fm) >= 1e-6) {
        /*累加當前項*/
        s += (fz / fm);
        /*準備下一項*/
        fz *= (++i);
        fm *= 2 * i + 1;
    }
    printf("%.2lf", s * 2);
}

12.求Π的值:根據以下公式求Π的近似值,要求累加到某項的絕對值小于1e-6時為止,

image-20200818104643884

#include <stdio.h>
#include <math.h>

void main() {
    double fz = 1, fm = 1, s = 0, t = 1;
    while (fabs(fz / fm * t) >= 1e-6) {
        /*累加當前項*/
        s += (fz / fm * t);
        /*準備下一項*/
        fm += 2;
        /*改變符號值*/
        t = -t;
    }
    printf("%.2lf", s * 4);
}

13.求e的值:根據以下公式求e的近似值,要求累加到某項的絕對值小于1e-6時為止,

image-20200818104743329

#include <stdio.h>
#include <math.h>

void main() {
    double fz = 1, fm = 1, s = 1, i = 1;
    while (fabs(fz / fm) >= 1e-6) {
        /*累加當前項*/
        s += (fz / fm);
        /*準備下一項*/
        fm *= (++i);
    }
    printf("%.2lf", s);
}

14.求ex的值:根據以下公式求ex的近似值,要求累加到某項的絕對值小于1e-6時為止,

image-20200818104816454

#include <stdio.h>
#include <math.h>

void main() {
    double fz, fm, s = 1, i = 1, x;
    scanf("%lf", &x);
    fz = x;
    fm = 1;
    while (fabs(fz / fm) >= 1e-6) {
        /*累加當前項*/
        s += (fz / fm);
        /*準備下一項*/
        fz = pow(x, ++i);
        fm *= i;
    }
    printf("%.2lf", s);
}

15.求sinx的值:根據以下公式求sinx的近似值,要求累加到某項的絕對值小于1e-6時為止,

image-20200818104853039

#include <stdio.h>
#include <math.h>

void main() {
    double x, t, s = 0;
    int i = 0;
    scanf("%lf", &x);
    t = x;
    while (fabs(t) >= 1e-6) {
        s += t;
        i++;
        t *= -1 * (x * x) / (2 * i) / (2 * i + 1);
    }
    printf("%.2lf", s);
}

16.求cosx的值:根據以下公式求cosx的近似值,要求累加到某項的絕對值小于1e-6時為止,

image-20200818104922255

#include <stdio.h>
#include <math.h>

void main() {
    double x, t, s = 0;
    int i = 0;
    scanf("%lf", &x);
    t = 1;
    while (fabs(t) >= 1e-6) {
        s += t;
        i++;
        t *= -1 * (x * x )/ (2 * i) / (2 * i - 1);
    }
    printf("%.2lf", s);
}

17.求平方根:撰寫函式double getsqrt(double a),計算x=√a(只計算a=1,2,3,4,5的值),已知計算x=√a的迭代公式如下所示,要求累加到某項的絕對值小于1e-6時為止,

image-20200818104955712

#include <stdio.h>
#include <math.h>

double getsqrt(double a) {
    double x0, x1;
    x0 = a / 2;
    x1 = (x0 + a / x0) / 2;
    while (fabs(x0 - x1) >= 1e-6) {
        x0 = x1;
        x1 = (x0 + a / x0) / 2;
    }
    return x0;
}

void main() {
    int i;
    for (i = 1; i <= 5; i++) {
        printf("%.2lf\n", getsqrt(i));
    }
}

第八類、進制轉換(05道)

1.十進制(0~2147483647)轉任意進制(2進制~16進制),

#include <stdio.h>

void main() {
    int num, radix, i = 0;
    char res[32] = {0}, table[] = "0123456789ABCDEF";
    printf("請輸入一個十進制整數:");
    scanf("%d", &num);
    printf("請輸入要轉換為幾進制:");
    scanf("%d", &radix);
    if (num == 0) {
        res[0] = '0';
        i = 1;
    }
    while (num > 0) {
        res[i++] = table[num % radix];
        num /= radix;
    }
    printf("轉換結果:");
    while (--i >= 0) {
        printf("%c", res[i]);
    }
}

2.任意進制(2進制~16進制)轉十進制(0~2147483647),

#include <stdio.h>
#include <string.h>

void main() {
    int res = 0, radix, i, k = 1;
    char num[32], table[] = "0123456789ABCDEF";
    printf("請輸入待轉換的字串:");
    scanf("%s", &num);
    printf("待轉換字串為幾進制:");
    scanf("%d", &radix);
    for (i = strlen(num) - 1; i >= 0; i--) {
        res += (strchr(table, num[i]) - table) * k;
        k *= radix;
    }
    printf("轉換結果:%d", res);
}

3.輸入一個二進制字串,將其轉換為對應的十進制,

#include <stdio.h>

void main() {
    char s[10];
    int i, n;
    gets(s);
    for (n = i = 0; s[i] != '\0'; i++) {
        n = n * 2 + s[i] - '0';
    }
    printf("%d", n);
}

4.輸入一個八進制字串,將其轉換為對應的十進制,

#include <stdio.h>

void main() {
    char s[10];
    int i, n;
    gets(s);
    for (n = i = 0; s[i] != '\0'; i++) {
        n = n * 8 + s[i] - '0';
    }
    printf("%d", n);
}

5.輸入一個十六進制字串,將其轉換為對應的十進制,

#include <stdio.h>

void main() {
    char s[10];
    int i, n;
    gets(s);
    for (n = i = 0; s[i] != '\0'; i++) {
        if (s[i] >= '0' && s[i] <= '9')
            n = n * 16 + s[i] - '0';
        if (s[i] >= 'a' && s[i] <= 'z')
            n = n * 16 + s[i] - 'a' + 10;
        if (s[i] >= 'A' && s[i] <= 'Z')
            n = n * 16 + s[i] - 'A' + 10;
    }
    printf("%d", n);
}

第九類、實際應用(27道)

1.自由落體:一球從100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地時,共經過多宣告?第10次反彈多高?

#include <stdio.h>

void main() {
    double s = 100, h = s / 2;
    int i;
    for (i = 2; i <= 10; i++) {
        s = s + 2 * h;
        h = h / 2;
    }
    printf("s=%.6lf\n", s);
    printf("h=%.6lf\n", h);
}

2.計算天數:輸入年月日,求當天是那年的第幾天?

#include <stdio.h>

void main() {
    int y, m, d, s, i;
    scanf("%d%d%d", &y, &m, &d);
    s = d;
    for (i = 1; i < m; i++)
        if (i==1||i==3||i==5||i==7||i==8||i==10||i==12)
            s += 31;
        else if (i==4||i==6||i==9||i==11)
            s += 30;
        else if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
            s += 29;
        else
            s += 28;
    printf("%d", s);
}

3.獎金提成:企業發放的獎金根據利潤提成:

00萬元 < 利潤 <= 10 萬元,高出00萬元的部分,獎金可提成10%;

10萬元 < 利潤 <= 20 萬元,高出10萬元的部分,獎金可提成7.5%;

20萬元 < 利潤 <= 40 萬元,高出20萬元的部分,獎金可提成5%;

40萬元 < 利潤 <= 60 萬元,高出40萬元的部分,獎金可提成3%;

60萬元 < 利潤 <= 100萬元,高出60萬元的部分,獎金可提成1%;

100萬元< 利潤 ,高出100萬的部分,獎金可提成1%;

從鍵盤輸入當月利潤n,求應發放獎金總數?

#include <stdio.h>

void main() {
    double n,bonus,bonus10,bonus20,bonus40,bonus60,bonus100;
    printf("Please enter the total profit of the month:");
    scanf("%lf", &n);
    bonus10 = 100000 * 0.1;
    bonus20 = bonus10 + 100000 * 0.075;
    bonus40 = bonus20 + 200000 * 0.05;
    bonus60 = bonus40 + 200000 * 0.03;
    bonus100 = bonus60 + 400000 * 0.015;
    if (n <= 100000)
        bonus = n * 0.1;
    else if (n <= 200000)
        bonus = bonus10 + (n - 100000) * 0.075;
    else if (n <= 400000)
        bonus = bonus20 + (n - 200000) * 0.05;
    else if (n <= 600000)
        bonus = bonus40 + (n - 400000) * 0.03;
    else if (n <= 1000000)
        bonus = bonus60 + (n - 600000) * 0.015;
    else if (n > 1000000)
        bonus = bonus100 + (n - 1000000) * 0.01;
    printf("bonus=%lf", bonus);
}

4.出租車計價:根據某城市普通出租車收費標準撰寫程式計算車費,標準如下:起步里程為3公里,起步費10元;超起步里程后10公里內,每公里2元;超過10公里以上的部分加收50%的回空補貼費,即每公里3元;營運程序中,因路阻及乘客要求臨時停車的,按每5分鐘2元計收(不足5分鐘則不收費),輸入在一行中,給出輸入行駛里程(單位為公里,精確到小數點后1位)與等待時間(單位為分鐘),其間以空格分隔,輸出乘客應支付的車費(單位為元),結果四舍五入,保留到元,

#include <stdio.h>

void main() {
    double mile;
    int time;
    double price, price1, price2;
    scanf("%lf%d", &mile, &time);
    if (mile <= 3) {
        price1 = 10;
    } else if (mile <= 10) {
        price1 = 10 + (mile - 3) * 2.0;
    } else {
        price1 = 10 + (10 - 3) * 2.0 + (mile - 10) * 3.0;
    }
    price2 = time / 5 * 2;
    price = price1 + price2;
    printf("%.0f", price);
}

5.階梯電價:為了提倡居民節約用電,某省電力公司執行“階梯電價”,安裝一戶一表的居民用戶電價分為兩個“階梯”:月用電量50千瓦時(含50千瓦時)以內的,電價為0.53元/千瓦時;超過50千瓦時的,超出部分的用電量,電價上調0.05元/千瓦時,輸入某用戶的月用電量(單位:千瓦時),計算該用戶應支付的電費(元),結果保留兩位小數,

#include <stdio.h>

void main() {
    float ydl, df;
    scanf("%f", &ydl);
    if (ydl <= 50)
        df = 0.53 * ydl;
    else
        df = 0.53 * 50 + (ydl - 50) * 0.58;
    printf("%.2f", df);
}

6.學生成績分布:讀入N個學生的百分制成績,統計五分制成績的分布,百分制成績到五分制成績的轉換規則:大于等于90分為A;小于90且大于等于80為B;小于80且大于等于70為C;小于70且大于等于60為D;小于60為E,輸入在第一行中給出一個正整數N(≤1000),即學生人數;第二行中給出N個學生的百分制成績,其間以空格分隔,在一行中輸出A、B、C、D、E對應的五分制成績的人數分布,數字間以空格分隔,行末不得有多余空格,

#include <stdio.h>

void main() {
    int a, b, c, d, e, n, i, arr[1000] = {0};
    scanf("%d", &n);
    a = b = c = d = e = 0;
    for (i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
        if (arr[i] >= 90)
            a++;
        else if (arr[i] >= 80)
            b++;
        else if (arr[i] >= 70)
            c++;
        else if (arr[i] >= 60)
            d++;
        else
            e++;
    }
    printf("%d %d %d %d %d", a, b, c, d, e);
}

7.問星期:請輸入星期幾的第一個字母來判斷一下是星期幾,如果第一個字母一樣,則繼續判斷第二個字母,

#include <stdio.h>

void main() {
    char w;
    printf("請輸入第一個字母:");
    scanf("%c", &w);
    getchar();
    switch (w) {
        case 'M' :printf("周一");break;
        case 'W' :printf("周三");break;
        case 'F' :printf("周五");break;
        case 'S' :
            printf("請輸入第二個字母:");
            scanf("%c", &w);
            switch (w) {
                case 'u' :printf("周日");break;
                case 'a' :printf("周六");break;
            }
            break;
        case 'T' :
            printf("請輸入第二個字母:");
            scanf("%c", &w);
            switch (w) {
                case 'u' :printf("周二");break;
                case 'h' :printf("周四");break;
            }
            break;
    }
}

8.字符統計:輸入一行字符,分別統計出其中英文字母、空格、數字和其它字符的個數,

#include <stdio.h>

void main() {
    int letters = 0, spaces = 0, digits = 0, others = 0;
    char c;
    while ((c = getchar()) != '\n') {
        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
            letters++;
        else if (c == ' ')
            spaces++;
        else if (c >= '0' && c <= '9')
            digits++;
        else
            others++;
    }
    printf("l=%d,d=%d,s=%d,o=%d", letters, digits, spaces, others);
}

9.報數問題:有n個人圍成一圈,順序排號,從第一個開始報數(從1到3報數),凡報到3的人退出圈子,問最后留下的是原來第幾號的那位,

#include <stdio.h>

void main() {
    int a[1000], n, t, c, i;
    scanf("%d", &n);
    t = n;
    for (i = 0; i < t; i++) {
        a[i] = i + 1;
    }
    for (i = c = 0; n > 1; i++) {
        /* 從頭開始嗎 */
        if (i == t) {
            i = 0;
        }
        /* 退圈的不管 */
        if (a[i] != 0) {
            c++;
        }
        /* 數到三退圈 */
        if (c == 3) {
            a[i] = 0;
            c = 0;
            n--;
        }
    }
    for (i = 0; i < t; i++) {
        if (a[i] != 0) {
            printf("%d", a[i]);
        }
    }
}

10.資料加密:某個公司采用公用電話傳遞資料,資料是四位的整數,在傳遞程序中是加密的,加密規則如下:每位數字都加上5,然后用和除以10的余數代替該數字,再將第一位和第四位交換,第二位和第三位交換,然后按照相反的順序依次輸出,

#include <stdio.h>
#define N 4

void main() {
    int a, i, t, data[N];
    scanf("%d", &a);
    data[0] = a % 10;
    data[1] = a / 10 % 10;
    data[2] = a / 100 % 10;
    data[3] = a / 1000;
    for (i = 0; i < N; i++) {
        data[i] += 5;
        data[i] %= 10;
    }
    for (i = 0; i < N / 2; i++) {
        t = data[i];
        data[i] = data[N - 1 - i];
        data[N - 1 - i] = t;
    }
    for (i = 0; i < N; i++) {
        printf("%d", data[N - 1 - i]);
    }
}

11.一維陣列:輸入n個(1<n<=10)正整數并保存到陣列中,求出最大值、最小值、平均值以及最大值、最小值在陣列中的下標分別是多少,

#include <stdio.h>

void main() {
    int i, n, max = 0, min = 0, sum = 0, a[10];
    float avg;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        sum += a[i];
    }
    avg = (float) sum / n;
    for (i = 0; i < n; i++) {
        if (a[i] > a[max])
            max = i;
        if (a[i] < a[min])
            min = i;
    }
    printf("max=%d,index=%d\n", a[max], max);
    printf("min=%d,index=%d\n", a[min], min);
    printf("avg=%.2f\n", avg);
}

12.字符加密:撰寫加密函式:int encode(int *c)、解密函式:int decode(int *c),主函式輸入一些純字符,呼叫加密演算法對這些字符進行加密,加密方式:每個字符的碼值+13,然后再呼叫解密函式將加密后的字符依次輸出,

#include <stdio.h>

/* 加密演算法 */
int encode(int *c) {
    *c = *c + 13;
    return *c;
}

/* 解密演算法 */
int decode(int *c) {
    *c = *c - 13;
    return *c;
}

void main() {
    int c[100], i;
    i = 0;
    while ((c[i] = getchar()) != '\n') {
        putchar(encode(&c[i]));
        i++;
    }
    printf("\n");
    i = 0;
    while (c[i] != '\n') {
        putchar(decode(&c[i]));
        i++;
    }
    printf("\n");
}

13.數字提取:輸入一個以回車為結束標志的字串(少于10個字符),提取其中的所有數字字符,將其轉換成一個十進制整數輸出,

#include <stdio.h>

void main() {
    char str[10];
    int i = 0, n = 0;
    gets(str);
    while (str[i] != '\0') {
        if (str[i] >= '0' && str[i] <= '9') {
            n = n * 10 + str[i] - '0';
        }
        i++;
    }
    printf("num=%d\n", n);
}

14.漁民打魚:中國有句俗語叫“三天打魚兩天曬網”,假設某人從某天起,開始“三天打魚兩天曬網”,問這個人在以后得第N天中是“打魚”還是“曬網”?

#include <stdio.h>

void main() {
    int day;
    scanf("%d", &day);
    if (day % 5 == 1 || day % 5 == 2 || day % 5 == 3) {
        printf("Fishing in day %d\n", day);
    } else {
        printf("Drying in day %d\n", day);
    }
}

15.小球重量:三個球A、B、C,大小形狀相同且其中一個球與其它球重量不同,要求找出這個不一樣的球,

#include <stdio.h>

void main() {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if (a == b)
        printf("C\n");
    else if (a == c)
        printf("B\n");
    else
        printf("A\n");
}

16.學生捐款:在全校1000名學生中,征集慈善募捐,當募捐總數達到10萬元時就停止募捐,統計此時的捐款人數以及平均每人捐款的數目,

#include <stdio.h>

void main() {
    float amount, avg, sum = 0;
    int i;
    for (i = 1; i <= 1000; i++) {
        printf("請輸入捐款金額:");
        scanf("%f", &amount);
        sum = sum + amount;
        if (sum >= 100000) {
            break;
        }
    }
    if (i <= 1000) {
        printf("募捐已經完成,資訊如下:\n");
        avg = sum / i;
    } else {
        printf("募捐沒有完成,資訊如下:\n");
        avg = sum / (--i);
    }
    printf("捐款人數=%d,平均金額=%.2f\n", i, avg);
}

17.遞回轉換:用遞回的方法將一個整數轉換為字串,例如:輸入123456,輸出“123456”,

#include <stdio.h>

void tranvers(int n) {
    if (n / 10 != 0)
        tranvers(n / 10);
    printf("%c", n % 10 + '0');
}

void main() {
    int n;
    printf("Please enter a number:");
    scanf("%d", &n);
    printf("The string is ");
    if (n < 0) {
        printf("-");
        n = -n;
    }
    tranvers(n);
}

18.火車時間:假設出發和到達在同一天內,根據火車的出發時間和到達時間,撰寫程式計算整個旅途所用的時間,輸入格式:在一行中輸入兩個4位正整數,分別表示火車的出發時間和到達時間,每個時間的格式為2位小時數(00-23)和2位分鐘數(00-59),輸出格式:“hh:mm”,其中hh為2位小時數、mm為2位分鐘數,

#include <stdio.h>

void main() {
    int ks, js, xs, fz;
    scanf("%d%d", &ks, &js);
    xs = js / 100 - ks / 100;
    fz = js % 100 - ks % 100;
    if (fz < 0) {
        xs = xs - 1;
        fz = 60 + fz;
    }
    printf("%02d:%02d", xs, fz);
}

19.簡單計算器:撰寫一個簡單計算器的程式,可根據輸入的運算子,對2個整數進行加、減、乘、除或求余運算,且保證除法和求余的分母非零,當運算子為+、-、*、/、%時,輸出相應的運算結果,若輸入是非法符號則輸出ERROR,

#include <stdio.h>

void main() {
    int a, b;
    char c;
    scanf("%d %c%d", &a, &c, &b);
    switch (c) {
        case '+': printf("%d\n", a + b); break;
        case '-': printf("%d\n", a - b); break;
        case '*': printf("%d\n", a * b); break;
        case '/':
            if (b != 0) {
                printf("%d\n", a / b);
                break;
            }
        case '%':
            if (b != 0) {
                printf("%d\n", a % b);
                break;
            }
        default :
            printf("ERROR\n");
            break;
    }
}

20.機動車處理:按照規定,在高速公路上行駛的機動車,達到或超出本車道限速的10%,則初200元罰款;達到或超出本車道限速的50%,就要吊銷駕駛證,撰寫程式根據車速和限速自定判別對該機動車的處理,輸入兩個整數,分別對應車速和限速,輸出格式:若屬于正常駕駛,則輸出“OK”;若屬于罰款,則輸出“Exceed x%. Ticket 200”;若應該吊銷駕駛證,則輸出“Exceed x%. License Revoked”,其中,x是超速的百分比,精確到整數,

#include <stdio.h>

void main() {
    int cs, xs, n, m;
    scanf("%d%d", &cs, &xs);
    n = xs * (1 + 0.1);
    m = xs * (1 + 0.5);
    if (cs < n) {
        printf("OK\n");
    } else if (cs < m) {
        printf("Exceed %.0f%%. Ticket 200\n",
                1.0 * (cs - xs) / xs * 100);
    } else {
        printf("Exceed %.0f%%. License Revoked\n",
                1.0 * (cs - xs) / xs * 100);
    }
}

21.階梯水費:為鼓勵居民節約用水,自來水公司按用水量階梯式計價的辦法,居民應交水費y(元)與月用水量x(噸)相關:當x不超過15噸時,y=4x/3;超過后,y=2.5x-17,請撰寫程式實作水費的計算,

#include <stdio.h>

void main() {
    float x, y;
    scanf("%f", &x);
    if (x >= 0 && x <= 15)
        y = 4 * x / 3;
    else
        y = 2.5 * x - 17;
    printf("%.2f\n", y);
}

22.蠕蟲爬井:一條蠕蟲長1寸,在一口深為N寸的井的底部,已知蠕蟲每1分鐘可以向上爬U寸,但必須休息1分鐘才能接著往上爬,在休息的程序中,蠕蟲又下滑了D寸,就這樣,上爬和下滑重復進行,問蠕蟲需要多長時間才能爬出井?要求不足1分鐘按1分鐘計算,假定只要在某次上爬程序中蠕蟲的頭部到達了井的頂部,那么蠕蟲就完成任務了,初始時,蠕蟲是趴在井底的(即高度為0),輸入格式:輸入在一行中順序給出3個正整數N、U、D,其中D<U,N不超過100但必須大于0,輸出格式:在一行中輸出蠕蟲爬出井的時間,以分鐘為單位,

#include <stdio.h>

void main() {
    int n, u, d, time = 0, curh = 0;
    /* 輸入井的深度,蠕蟲上爬和下滑的距離 */
    scanf("%d%d%d", &n, &u, &d);
    while (1) {
        time++;
        curh += u; /* 每爬一次,上升 u 距離 */
        if (curh >= n) break;
        time++;
        curh -= d; /* 休息一次,下滑 d 距離 */
    }
    printf("%d\n", time);
}

23.汽油自助服務:現在90號汽油6.95元/升、93號汽油7.44元/升、97號汽油7.93元/升,為吸引顧客,某自動加油站推出了“自助服務”和“協助服務”兩個服務等級,分別可得到5%和3%的折扣,撰寫程式,根據輸入顧客的加油量a,汽油品種b(90、93或97)和服務型別c(m – 自助,e – 協助),計算并輸出相應付款,

#include <stdio.h>

void main() {
    float je, jg;
    int a, b;
    char c;
    scanf("%d %d %c", &a, &b, &c);
    switch (b) {
        case 90:
            jg = 6.95;
            break;
        case 93:
            jg = 7.44;
            break;
        case 97:
            jg = 7.93;
            break;
    }
    if (c == 'm') {
        je = jg * a * (1 - 0.05);
    } else {
        je = jg * a * (1 - 0.03);
    }
    printf("%.2f", je);
}

24.四舍五入:編程實作將浮點數“123.456789”分別四舍五入保留1位小數、2位小數和3位小數,

#include <stdio.h>

void main() {
    float a = 123.456789;
    float f1 = (int) ((a * 10) + 0.5) / 10.0;    //保留1位小數
    float f2 = (int) ((a * 100) + 0.5) / 100.0;  //保留2位小數
    float f3 = (int) ((a * 1000) + 0.5) / 1000.0;//保留3位小數
    printf("f1 = %0.1f\n", f1);
    printf("f2 = %0.2f\n", f2);
    printf("f3 = %0.3f\n", f3);
}

25.節目調查:調查電視節目受歡迎程度,某電視臺要調查觀眾對該臺8個欄目(設相應欄目編號為1-8)的受歡迎程度,共調查了1000位觀眾,現要求撰寫程式,輸入每一位觀眾的投票情況(每位觀眾只能選擇一個最喜歡的欄目投票),統計輸出各欄目的得票情況,

#include <stdio.h>

void main() {
    int i, n, a[9] = {0};
    for (i = 1; i <= 1000; i++) {
        scanf("%d", &n);
        a[n]++;
    }
    for (i = 1; i <= 8; i++) {
        printf("欄目%d得票=%d\n", i, a[i]);
    }
}

26.由用戶輸入一個正整數n,分析出該正整數的每一位,然后將各位數字從大到小重新排序后得到正整數m,輸出m和n的平均值,

(1)撰寫輸出正整數n和m的程式,

(2)給出除錯過的輸出m和n的平均值的源程式,

#include <stdio.h>
#include <stdlib.h>

/**
 * 選擇排序法
 * @param a     排序陣列
 * @param len   元素個數
 */
void selction_sort(int a[], int len) {
    int i, j, t;
    for (i = 0; i < len - 1; i++) {
        for (j = i + 1; j < len; j++) {
            if (a[i] < a[j]) {
                t = a[i];
                a[i] = a[j];
                a[j] = t;
            }
        }
    }
}

void main() {
    int m, n, t, i, c, *p;
    /*輸入數字n*/
    scanf("%d", &n);
    /*分析位數c*/
    t = n;
    c = 0;
    while (t > 0) {
        c++;
        t /= 10;
    }
    /*分解數字n*/
    p = (int *) malloc(sizeof(int) * c);
    for (t = n, i = 0; i < c; i++) {
        p[i] = t % 10;
        t /= 10;
    }
    /*排序陣列p*/
    selction_sort(p, c);
    /*陣列還原m*/
    for (m = 0, i = 0; i < c; i++) {
        m = m * 10 + p[i];
    }
    /*輸出結果*/
    printf("n = %d\n", n);
    printf("m = %d\n", m);
    printf("(m + n) / 2 = %.2lf", ((m + n) / 2.0));
}

27.現有撲克牌52張,其花色記錄為:char suit[4][5] = {“紅心”, “方塊”, “梅花”, “黑桃”};其牌面記錄為:char face[] = {‘A’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘X’, ‘J’, ‘Q’, ‘K’};請用C語言撰寫程式實作以下功能,

(1)自定義結構體陣列,按照同一花色牌面從小到大順序記錄全部52張撲克牌,

(2)以時間為引數設定隨機序列種子,實作洗牌:即遍歷撲克牌陣列,依次交換當前牌與陣列中隨機位置的牌,

(3)輸出打亂順序后的全部撲克牌,牌與牌間使用Tab分隔,

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

typedef struct card {
    int type;/*代表花色下標*/
    int point;/*代表點數下標*/
} Card;

void main() {
    int i, j, k, index;
    Card c[52], t;
    char suit[4][5] = {"紅心", "方塊", "梅花", "黑桃"};
    char face[] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'X', 'J', 'Q', 'K'};

    /*初始化52張牌,由k控制這是第幾張牌*/
    k = 0;
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 13; j++) {
            c[k].type = i;
            c[k].point = j;
            k++;
        }
    }

    /*回圈這52張牌,使用亂數進行洗牌*/
    srand(time(NULL));
    for (i = 0; i < 52; i++) {
        /*產生0~51的亂數*/
        index = rand() % 52;
        /*交換兩張牌的位置*/
        t = c[i];
        c[i] = c[index];
        c[index] = t;
    }

    /*輸出這52張牌,由k控制這是第幾張牌*/
    k = 0;
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 13; j++) {
            printf("%s%c\t", suit[c[k].type], face[c[k].point]);
            k++;
            if (k % 13 == 0) {
                printf("\n");
            }
        }
    }
}

第十類、圖形輸出(09道)

1.左上三角

#include <stdio.h>

void main() {
    int i, j;
    for (i = 10; i >= 1; i--) {
        for (j = 1; j <= i; j++)
            printf("*");
        if (i != 1)
            printf("\n");
    }
}

2.左下三角

#include <stdio.h>

void main() {
    int i, j;
    for (i = 1; i <= 10; i++) {
        for (j = 1; j <= i; j++)
            printf("*");
        if (i != 10)
            printf("\n");
    }
}

3.右上三角

#include <stdio.h>

void main() {
    int i, j;
    for (i = 10; i >= 1; i--) {
        for (j = 1; j <= 10 - i; j++)
            printf(" ");
        for (j = 1; j <= i; j++)
            printf("*");
        if (i != 1)
            printf("\n");
    }
}

4.右下三角

#include <stdio.h>

void main() {
   int i, j;
   for (i = 1; i <= 10; i++) {
       for (j = 1; j <= 10 - i; j++)
           printf(" ");
       for (j = 1; j <= i; j++)
           printf("*");
       if (i != 10)
           printf("\n");
   }
}

5.輸出楊輝三角形

#include <stdio.h>

void main() {
    int i, j, n, a[100][100] = {0};
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        a[i][0] = 1;
    }
    for (i = 1; i < n; i++) {
        for (j = 1; j <= i; j++) {
            a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
        }
    }
    for (i = 0; i < n; i++) {
        for (j = 0; j <= i; j++) {
            printf("%-4d", a[i][j]);
        }
        printf("\n");
    }
}

6.輸出數字金字塔

#include <stdio.h>

void main() {
    int i, j;
    for (i = 1; i <= 9; i++) {
        for (j = 9; j > i; j--)
            printf(" ");
        for (j = 1; j <= i; j++)
            printf("%c", 48 + j);
        for (j = i - 1; j >= 1; j--)
            printf("%c", 48 + j);
        if (i != 9)
            printf("\n");
    }
}

7.列印乘法口訣表,

#include <stdio.h>

void main() {
    int i, j;
    for (i = 1; i <= 9; i++) {
        for (j = 1; j <= i; j++)
            printf("%d * %d = %-5d", i, j, i * j);
        if (i != 9)
            printf("\n");
    }
}

8.輸出空心菱形

#include <stdio.h>

void main() {
    /*n:代表菱形邊長*/
    int i, j, n = 5;
    /*列印上三角*/
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= (2 * n - 1); j++) {
            if (j == n + 1 - i || j == n - 1 + i)
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }
    /*列印下三角*/
    for (i = 1; i < n; i++) {
        for (j = 1; j <= (2 * n - 1); j++) {
            if (j == i + 1 || j == (2 * n - 1) - i)
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }
}

9.輸出實心菱形

#include <stdio.h>

void main() {
    /*n:代表菱形邊長*/
    int i, j, n = 5;
    /*列印上三角*/
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= (2 * n - 1); j++) {
            if (j >= n + 1 - i && j <= n - 1 + i)
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }
    /*列印下三角*/
    for (i = 1; i < n; i++) {
        for (j = 1; j <= (2 * n - 1); j++) {
            if (j >= i + 1 && j <= (2 * n - 1) - i)
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/136333.html

標籤:其他

上一篇:Spring中集成Groovy的四種方式

下一篇:征服阿里P7的Spring回圈依賴原理決議,高薪offer唾手可得

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more