第三次作业

1、编写程序,使用scanf()函数接受整型、实型、字符型的变量,并分行依次输出。

#include <stdio.h>
main()
{
    int a;
    float b;
    char c;
    scanf("%d%f%c",&a,&b,&c);
    printf("%d%f%c",a,b,c);

}

 

 2.编写程序,通过scanf()函数接收两个字符型变量,并输出。

#include <stdio.h>
main()
{
    char a,b;
    scanf("%c%c",&a,&b);
    printf("%c%c",a,b);
}

 

 3编写一个程序,接收圆柱体的底面半径和高,输出其体积(结果保留两位小数)。

#include <stdio.h>
main()
{
    double h,r,s,p=3.14;
    printf("请输入圆柱底面半径\n");
    scanf("%lf",&r);
    printf("请输入圆柱高");
    scanf("%lf",&h);
    s=p*r*r*h;
    printf("%.2lf",s);
}

 

 5输入一个小写字母,转换成大写字母。

#include <stdio.h>
main()
{
    char a,b;
    printf("输入一个小写字母");
    scanf("%c",&a);
    b=a-32;
    printf("他的大写字母为%c\n",b);
}

 

 

6.超市购物结算
#include<stdio.h>
main()
{
   float a,b,sum,da,fu,zhao;
   printf("欢迎光临\n请输入购买商品数量");
   scanf("%f",&a);
   printf("请输入商品单价");
   scanf("%f",&b);
   sum=a*b;
   printf("您所消费总金额为%.2f",sum);
   da=(int)(sum*0.8);
   printf("打折取整后金额为%d",da);
   printf("你支付金额为");
   scanf("%f",&fu);
   zhao=fu-da;
   printf("找您%.2f\n欢迎下次光临",zhao);
}

 

posted @ 2021-10-19 11:32  崔花钱  阅读(7)  评论(0编辑  收藏  举报