第七次作业

  1. 1.编写程序,判断一个数n是正数还是负数。
    
    #include<stdio.h>
    main()
    {
        float n;
        scanf("%f",&n);
        if(n>0)
            printf("正数!\n");
        else if(n==0)
            printf("0既不是正数,也不是负数!\n");
        else
            printf("负数\n");
    }

     

     

    2.编写程序,计算出租车的行驶距离与费用之间的关系。起步3km内,8元;之后1.6元/km。
    
    #include<stdio.h>
    main()
    {
        float s,l;
        printf("输入的行驶距离:\n");
        scanf("%f",&l);
        if(l<=3)
            s=8;
        else
            s=(l-3)*1.6+8;
        printf("%.2f\n",s);
    }

     

     

    3.输入一个数,判断是奇数还是偶数。
    
    #include<stdio.h>
    main()
    {
        int num;
        scanf("&d",&num);
        if(num%2==0)
            printf("偶数\n");
        else
            printf("奇数\n");
    }

     

     

    4.输入一个数,输出它的绝对值(负数*-1就是绝对值)。
    
    #include<stdio.h>
    main()
    {
        int x;
        scanf("%d",&x);
        if(x<0)
            x=-x;
        printf("%d",x);
        return 0;
    }

     

     

    5.输入2个数,输出较大数。
    
    #include<stdio.h>
    main()
    {
        int a,b;
        printf("输入一个数");
        scanf("%d",&a);
        printf("输入另一个数");
        scanf("%d",&b);
        if(a>=b)
            printf("最大的数为%d",a);
        else
            printf("最大的数为%d",b);
    }

    6.输入一个字符,如果是大写就转成小写,如果是小写,就转成大写并输出。
    
    #include<stdio.h>
    main()
    {
        char x,y;
        printf("请输入一个字母:");
        scanf("%c",&x);
        if(x>='a'&&x<='z')
            y=x-32;
        if(x>='A'&&x<='Z')
            y=x+32;
        printf("转换后的字符为:%c\n",y);
    }

     

     

     

     

     

posted @ 2021-11-20 16:59  coldlane  阅读(7)  评论(0编辑  收藏  举报