知道长方形的长和宽,求面积和周长
#include
main()
{
float x,y,a,b;
printf ("请输入长和宽且用逗号分隔:);
scanf ("%f,%f,&x,&y);
a=x*y;
b=(x+y)*2;
printf ("面积=%f,周长=%f\n",a,b);
}
#include <stdio.h>
main()
{
float x,y,a,b;
printf("Please input length and width of rectangle with comma divided:");
scanf("%f,%f",&x,&y);
a = x * y;
b = ( x + y ) * 2;
printf(" area = %f, girth = %f", a, b);
提示的什么错误呢?给个明确的
printf("请输入长和宽且用逗号分隔:");printf ("面积=%f,周长=%f\n",a,b);引号要双的,书写习惯不好
scanf ("%f",&x);
scanf ("%f",&y);
读取字符串一行一行读取
scanf ("%f,%f",&x,&y);
少了个引号吧
printf ("请输入长和宽且用逗号分隔:); ------->>>> printf ("请输入长和宽且用逗号分隔:");
scanf ("%f,%f,&x,&y); ------->>>> scanf ("%f,%f",&x,&y);
#include <stdio.h>
main()
{
float x,y,a,b;
printf("Please input length and width of rectangle with comma divided:");
scanf("%f,%f",&x,&y);
a = x * y;
b = ( x + y ) * 2;
printf(" area = %f, girth = %f", a, b);
}
语句printf ("请输入长和宽且用逗号分隔:);和scanf ("%f,%f,&x,&y);的左边都少了双引号
头文件也有问题,应该是:#include
int main()
{
}