姓名:罗志明?实验地点:家中??实验时间:2020.03.25
#include<stdio.h>
main()
{
int l,w,h;
printf("请输入箱子的长、宽、高:\n");
scanf("%d%d%d",&l,&w,&h);
if(l==w&&w==h)
{
printf("该箱子是正方体.\n");
}else{
printf("该箱子是长方体,\n");
}
}
#include<stdio.h>
main()
{
int a,b,c,d,e;
printf("请输入打印纸,墨盒,光盘的数量:");
scanf("%d%d%d",&a,&b,&c);
d=18*a+132*b+4.5*c;
e=d/100;
switch(e)
{
case 0:
printf("应付款数:%f",18*a+132*b+4.5*c);break;
case 1:
printf("应付款数:%f",d*0.95);break;
case 2:
printf("应付款数:%f",d*0.94);break;
case 3:
printf("应付款数:%f",d*0.93);break;
case 4:
printf("应付款数:%f",d*0.92);break;
default:
printf("应付款数:%f",(18*a+132*b+4.5*c)*0.9);break;
}
}
#include<stdio.h>
main()
{
int year,month,days;
printf("please enter year and month:\n");
scanf("%d%d",&year,&month);
switch(month)
{
case 2:if((year%400==0)||((year%4==0)&&(year%100!=0)))
days=29;
else
days=28;
break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:days=31;break;
case 4:
case 6:
case 9:
case 11:days=30;break;
defult:printf("error");
}
printf("天数为:%d",days);
}
#include<stdio.h>
main()
{
int x,n,y;
float sum=0.0;
printf("请选择:1.日用品 2.文具 3.食品\n");
scanf("%d,&x");
switch(x)
{
case 1:printf("请选择:1.牙膏(3.5元/支) 2.牙膏(6.2元/支)\n");
printf(" 3肥皂(2元/块) 4.毛巾(8.6元/条)\n");
scanf("%d",&y);
printf("数量?");
scanf("%d",&n);
switch(y)
{
case 1:sum=n*3.5;break;
case 2:sum=n*6.2;break;
case 3:sum=n*2.0;break;
case 4:sum=n*8.6;break;
}
break;
case 2:printf("请选择:1.笔(3元/支) 2.笔记本(1.2元/个)\n");
printf(" 3文件夹(12元/个) 4.毛巾(8.6元/个)\n");
scanf("%d",&y);
printf("数量?");
scanf("%d",&n);
switch(y)
{
case 1:sum=n*3;break;
case 2:sum=n*1.2;break;
case 3:sum=n*12;break;
case 4:sum=n*8.6;break;
}
break;
case 3:printf("请选择:1.白糖(3.6元/包) 2.盐(1元/包)\n");
printf(" 3饼(2元/个) 4.方便面(3.6元/条)\n");
scanf("%d",&y);
printf("数量?");
scanf("%d",&n);
switch(y)
{
case 1:sum=n*3.6;break;
case 2:sum=n*1;break;
case 3:sum=n*2;break;
case 4:sum=n*3.6;break;
}
break;
}
printf("总计:%.2f元\n",sum);
}
#include<stdio.h>
main()
{
double x=1000/3.0;
double y=x-333.0;
double z=3*y-1.0;
printf("x=%lf\n",x);
printf("y=%lf\n",y);
printf("z=%lf\n",z);
if(z==0) printf("z==0.\n");
else printf("z不等于0.\n");
}
#include<stdio.h>
main()
{
int num=20;
if(5<num&&num<10)
printf("%d in range (5,10)!\n",num);
else
printf("%d out of range (5,10)!\n",num);
}
(1)只能进行四则运算
(2)采用switch--case结构,根据操作符的种类不同,进行不同的运算。
(3)考虑除法的特殊情况,即当除数为零时,出现.异常
流程图
#include<stdio.h>
main()
{
printf("请输入算式");
float a,b,c;
char x;
scanf("%f%c%f",&a,&x,&b);;
switch(x)
{
case‘+‘:c=a+b;
break;
case‘-‘:c=a-b;
break;
case‘*‘:c=a*b;
break;
case‘/‘:if(b!=0)
c=a/b;
else
printf("除数不能为0,请重新输入");
break;
default:
printf("error");
}
printf("%f%c%f=%f\n",x,a,b,c);
}
原文:https://www.cnblogs.com/lzm1689620688/p/12589795.html