#include <stdio.h>
//#include <conio.h> // Non-standard and not required!
int main()
{
float areaoc,areaor,peroc,peror,l,b,r,pi;
pi=3.14;
printf("Enter the length and breadth of rectangle: ");
scanf("%.2f %.2f",&l,&b);
printf("Enter the radius of circle: ");
scanf("%.2f",&r);
areaor=l*b;
peror=2*(l+b);
areaoc=pi*r*r;
peroc=2*pi*r;
printf("the area of rectangle is: %.2f ",areaor);
printf("the perimeter of rectangle is: %.2f ",peror);
printf("the area of circle is: %.2f ",areaoc);
printf("the perimeter of circle is: %.2f ",peroc);
return 0;
}
为什么我只输入一个值然后显示结果?
您应该这样执行scanf()语句:
scanf("%f %f",&l,&b);
然后您应该能够将2个输入值存储到两个给定的float变量中,这里是l(length)和b(breadth)。
指定仅在printf语句上应在浮点数后显示多少个数字的指定状态。