为什么我的代码在要求打印长度和宽度的值后不接受多个输入?

问题描述 投票:0回答:1
#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;
}

为什么我只输入一个值然后显示结果?

c++ c scanf
1个回答
0
投票

您应该这样执行scanf()语句:

scanf("%f %f",&l,&b);

然后您应该能够将2个输入值存储到两个给定的float变量中,这里是l(length)和b(breadth)。

指定仅在printf语句上应在浮点数后显示多少个数字的指定状态。

© www.soinside.com 2019 - 2024. All rights reserved.