scanf("%f,%f",&r,&h);
l=2*pi*r;
v=pi*r*r*h;
printf("圆周长为:%6.2f\n",l);
printf("%圆柱体积为:6.2f",v);
}
运行结果:(具体情况根据自己输入的数据而定)
如在键盘上输入:5,6↙
则运行结果为:
圆周长为:31.42
圆柱体积为:471.24
4.输入一个摄氏温度,要求输出华氏温度,公式为f = 5/9·c+32。
程序清单如下:
#include "stdio.h"
main( )
{
float c,f;
scanf("%f",&c);
f=5.0/9*c+32;
printf("%5.2f\n",c);
}
运行结果:(具体情况根据自己输入的数据而定)
如在键盘上输入:37↙
则运行结果为:
52.56
实验2 选择结构
任务1 if语句程序设计
1.修改下列程序,使之满足输入10时输出“= =”,否则输出“!=”的条件。 #include"stdio.h"
main()
{int x;
scanf("%d",&x);
if(x==10)printf("==\n");
else printf("!=\n");
}
2.修改下列程序,使之实现以下功能:① 当a= =b并且b==c时,输出“a==b==c”;② 当a!=b时,输出“a!=b”。
#include “stdio.h”
main( )
{ int a,b,c;
scanf(“%d%d%d”,&a,&b,&c);
if (a==b)
{if(b==c)
printf(“a==b==c”);
}
else