C语言程序设计作业2023/11/16

本次作业提交内容为第六章课后题第104页的6-2、6-4、6-5

【实验过程】

#include <stdio.h>

int main() {

    int x;

    scanf_s(“%d”, &x);

    if (x < 1) {

        printf(“%d\n”, x);

    }

    else if (x<10)

    {

        printf(“%d\n”, x * 2 – 1);

    }

    else

        printf(“%d\n”, x * 3 – 11);

    return 0;

}

【实验过程】

#include<stdio.h>

int main(){

    double gongzi = 500;

    int k, xiaoshou;                                                                                                                                              

    scanf_s(“%d”, &xiaoshou);

    if (xiaoshou % 1000 == 0)

         k = xiaoshou / 1000;

    else

         k = xiaoshou / 1000 + 1;

    switch (k) {

         case 0:

         case 1:

         case 2:

             break;

         case 3:

         case 4:

         case 5:

             gongzi += xiaoshou * 0.08;

             break;

         case 6:

         case 7:

         case 8:

         case 9:

         case 10:

             gongzi += xiaoshou * 0.1;

             break;

         default:

             gongzi += xiaoshou * 0.12;

             break;

    }

    printf(“%.2f\n”, gongzi);

    return 0;

}

【实验过程】

#include <stdio.h>

int main(){

    char c;

    printf(“输入一个字符:\n”);

    scanf_s(“%c”, &c,1);

    if (c >= 65 && c <= 90)

        printf(“输入的字符是大写字母\n”);

    else if (c >= 97 && c <= 122)

        printf(“输入的字符是小写字母\n”);

    else if (c >= 48 && c <= 57)

        printf(“输入的是数字\n”);

    else

        printf(“输入的是特殊符号\n”);

    return 0;

}


评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注