分类 C语言作业 下的文章

例:试找出满足下列条件的所有两位数
1) 其十位数不大于2
2) 将个位与十位对换,得到的两位数是原两位数
的两倍多

#include <stdio.h>

int main() {
    int i = 0;
    while (i <= 2) {
        int j = 0;
        while (j <= 9) {
            int num = i * 10 + j;
            int reversed = j * 10 + i;
            if (reversed >= num * 2 && reversed < num * 3) {
                printf("%d\n", num);
            }
            j++;
        }
        i++;
    }

    return 0;
}

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

int main() {
    float x, y, r;

    printf("请输入点M的坐标x: ");
    scanf_s("%f", &x);

    printf("请输入点M的坐标y: ");
    scanf_s("%f", &y);

    printf("请输入圆的半径: ");
    scanf_s("%f", &r);

    float d = sqrt(x * x + y * y);

    if (d < r) {
        printf("点M在圆内\n");
    }
    if (d == r) {
        printf("点M在圆上\n");
    }
    if (d > r) {
        printf("点M在圆外\n");
    }
    return 0;
}

#include <stdio.h>

int main() {
    float p, w, s, d, f;
    printf("请输入基本运费p,货物重w,距离s:\n");
    scanf_s("%f,%f,%f", &p, &w, &s);
    int n = s / 250;
    switch (n) {
    case 0:
        d = 0;
        break;
    case 1:
        d = 0.02;
        break;

    case 2:
    case 3:
        d = 0.05;
        break;

    case 4:
    case 5:
    case 6:
    case 7:
        d = 0.08;
        break;

    case 8:
    case 9:
    case 10:
    case 11:
        d = 0.1;
        break;
    default:
        d = 0.15;
        break;
    }
    f = p * w * s * (1 - d);
    printf("总运费f=%f\n", f);
    return 0;
}