请教C语言题目

1.编写一个C程序,显示下面的提示:Enterthelengthoftheroom:Enterthewidthoftheroom:在显示每个提示之后,你的程序可以接收键盘... 1.编写一个C 程序,显示下面的提示:
Enter the length of the room:
Enter the width of the room:
在显示每个提示之后,你的程序可以接收键盘的数据。在输入房间的长度(length)和宽度(width)之后,该程序可以计算和显示房间的面积。

2..编写一个程序从键盘输入圆柱体的半径r和高度h,计算其体积。

3.编写一个程序用于超市中的记账:已知苹果每千克5.0元,鸭梨每千克3.4元,香蕉每千克4.0元,橘子每千克2.4元,要求输入各类水果的销售重量,计算并输出应收款的数额。
展开
百度网友1eae159
2009-03-23 · TA获得超过157个赞
知道答主
回答量:36
采纳率:0%
帮助的人:42.7万
展开全部
/*1.编写一个C 程序,显示下面的提示:
Enter the length of the room:
Enter the width of the room:
在显示每个提示之后,你的程序可以接收键盘的数据。
在输入房间的长度(length)和宽度(width)之后,该程序可以计算和显示房间的面积。
*/
#include<stdio.h>
#include <stdlib.h>
void main()
{
float length,width,area;
char a;
loop: printf("Please enter the length of the room: ");
fflush(stdin); //清除键盘缓冲区
scanf("%f",&length);
printf("Please enter the width of the room: ");
fflush(stdin);
scanf("%f",&width);
area=length*width;
printf("According to your information, the area of this room is: %.4f\n",area);
printf("Continue or not? Please entre Y/N:"); //可以在不退出的情况下多次运行程序得出不同结果
fflush(stdin);
scanf("%c",&a);
if(a=='y'||a=='Y')
goto loop;
else
exit(0);
}
/*运行结果:
Please enter the length of the room: 12.3
Please enter the width of the room: 14.5
According to your information, the area of this room is: 178.3500
Continue or not? Please entre Y/N:y
Please enter the length of the room: 24.3
Please enter the width of the room: 13.6
According to your information, the area of this room is: 330.4800
Continue or not? Please entre Y/N:n*/
/*2..编写一个程序从键盘输入圆柱体的半径r和高度h,计算其体积。
*/
#include<iostream>
using namespace std;
void main()
{
double r,h,pi;char a;
pi=3.14;
loop: cout<<"请输入圆柱体的半径:";
cin>>r;
cout<<"请输入圆柱体的高:";
cin>>h;
cout<<"圆柱体的体积="<<r*r*h*pi<<endl;
cout<<endl<<"继续吗? 请输入 Y/N:";
fflush(stdin);
cin>>a;
if(a=='y'||a=='Y')
goto loop;
else
exit(0);
}
/*运行结果:
请输入圆柱体的半径:3
请输入圆柱体的高:4
圆柱体的体积=113.04

继续吗? 请输入 Y/N:n*/
//哎,用c++做简单多了
//老兄还是学c++吧
/*3.编写一个程序用于超市中的记账:
已知苹果每千克5.0元,鸭梨每千克3.4元,香蕉每千克4.0元,橘子每千克2.4元,
要求输入各类水果的销售重量,计算并输出应收款的数额。*/
#include<iostream>
using namespace std;
void main()
{
double apple,pear,banana,orange;
double apple_amount,pear_amount,banana_amount,orange_amount;
apple=5.0;
pear=3.4;
banana=4.0;
orange=2.4;
printf("请分别输入各类水果的销售重量:\n");
printf("苹果:");
cin>>apple_amount;
printf("鸭梨:");
cin>>pear_amount;
printf("香蕉:");
cin>>banana_amount;
printf("橘子:");
cin>>orange_amount;
cout<<"应付:"<<apple_amount*apple+pear_amount*pear+banana_amount*banana+orange_amount*orange<<endl;
}
/*运行结果:
请分别输入各类水果的销售重量:
苹果:1.2
鸭梨:1.1
香蕉:2.3
橘子:0
应付:18.94
*/
123ghg555
2009-03-23
知道答主
回答量:3
采纳率:0%
帮助的人:0
展开全部
eedf
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式