帮我编C语言,谢谢…… 问题是:从键盘输入矩形的长和宽,计算矩形的周长和面积。

如题所述

#include <stdio.h>

int main()
{
double width;
double height;

printf("请输入矩形的长:");
scanf("%lf%*c", &height);
printf("请输入矩形的宽:");
scanf("%lf%*c", &width);
printf("矩形周长:%lf\n", 2 * (height + width));
printf("矩形面积:%lf\n", height * width);
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-04-11
这个貌似应该自己写
#include<stdio.h>
void main()
{
float a,b;
scanf("%d %d",&a,&b);
printf("矩形的周长是%f",2*(a+b));
printf("矩形的面积是%f",a*b);

}
第2个回答  2011-02-28
#include<stdio.h>
int main()
{
float x,y;
printf("输入矩形的长和宽\n");
scanf("%f%f",&x,&y);
printf("周长为%f\n",2*(x+y));
printf("面积为%f\n",x*y);
return 0;

}
第3个回答  2011-02-28
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:\Documents and Settings\Owner\桌面>type hello.c
/* * * * * * * * * * * * * * * * * * * * * * * * * *
编译平台 : Windows XP
程序作者 : veket_linux
编译器 : GCC 3.4.2
* * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdio.h>
int main(void)
{
double l;
double w;
double c;
double s;
printf("input the length and width:\n");
scanf("%lf%lf",&l,&w);
c = 2 * (l + w);
s = l * w;
printf("c = %lf, s = %lf\n",c,s);
getchar();
return 0;
}
C:\Documents and Settings\Owner\桌面>gcc hello.c -o hello.exe
C:\Documents and Settings\Owner\桌面>hello.exe
input the length and width:
2.5 5.3
c = 15.600000, s = 13.250000
C:\Documents and Settings\Owner\桌面>
第4个回答  2011-02-28
#include <stdio.h>
int fun(int a,int b,int *x,int *y)
{
*x=(a+b)*2;
*y=a*b;
}
void main()
{
int a,b,l,s;
scanf("%d%d",&a,&b);
fun(a,b,&l,&s);
printf("l=%d,s=%d\n",l,s);
}
相似回答