第三次作业

1
2
3
4
5
6
7
8
9
10
1.  编写程序,使用scanf()函数接收整型、实型、字符型的变量,并分行依次输出。
#include<stdio.h>
main()
{
    int a;
    float b;
    char c;
    scanf("%d %f %c",&a,&b,&c);
    printf("%d\n%f\n%c\n",a,b,c);
}

  

 

 

1
2
3
4
5
6
7
8
.编写程序,通过餐费()函数接收两个字符型变量,并输出。
#include<stdio.h>
main()
{
    char a,c;
    scanf("%c %c",&a,&c);
    printf("%c %c\n",a,c);
}

  

 

 

1
2
3
4
5
6
7
8
9
10
3.编写程序,接收圆柱体底面半径和高,输出其体积(结果保留两位小数)。
#include<stdio.h>
#define PI 3.14
main()
{
    float h,r,v;
    scanf("%f %f",&r,&h);
    v=PI*r*r*h;
    printf("体积为:%.2f\n",v);
}

  

 

 

1
2
3
4
5
6
7
8
9
10
11
12
4.输入一个三位数,分别输出个位,十位,百位。
#include<stdio.h>
main()
{
    int a,ge,shi,bai;
    printf("请输入一个三位数");
    scanf("%d",&a);
    ge=a%10;
    shi=a/10%10;
    bai=a/100;
    printf("个位是%d,十位是%d,百位是%d\n",ge,shi,bai);
}

  

 

 

1
2
3
4
5
6
7
8
9
5.输入一个小写字母,转成大写并输出。
#include<stdio.h>
main()
{
    char a,b;
    scanf("%c",&a);
    b=a-32;
    printf("%c",b);
}

  

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
6.超市购物结算。(输入单价,数量,计算总金额,打八折,抹零,计算折后价,输入付款金额,计算找零)
#include<stdio.h>
main()
{
    double price,sum,pay,zhaoling;
    int num,moling;
    printf("请输入商品单价");
    scanf("%lf",&price);
    printf("请输入商品数量");
    scanf("%d",&num);
    sum=price*num;
    printf("您的消费总金额是%.2lf\n",sum);
    moling=(int)(sum*0.8);
    printf("八折抹零后需付款金额是%d",moling);
    printf("请输入付款金额");
    scanf("%lf",&pay);
    zhaoling=pay-moling;
    printf("您付款%lf元,找零%lf元",zhaoling);
}

  

 

posted @ 2021-11-25 12:25  粽子有点咸  阅读(14)  评论(0)    收藏  举报