平方根作为运行时的输入
Square-root as input at runtime
我正在用 C 编写代码来查找给定三角形是等边三角形、等腰三角形还是斜角三角形。我把它写成:
#include<stdio.h>
#include<math.h>
int main()
{
float x1,x2,x3,y1,y2,y3;
float d1,d2,d3;
printf("Enter the co-ordinates of 1st vertex: \n");
scanf("%f%f", &x1,&y1);
printf("Enter the co-ordinates of 2nd vertex: \n");
scanf("%f%f", &x2,&y2);
printf("Enter the co-ordinates of 3rd vertex: \n");
scanf("%f%f", &x3,&y3);
d1= sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
d2= sqrt((x1-x3)*(x1-x3) + (y1-y3)*(y1-y3));
d3= sqrt((x2-x3)*(x2-x3) + (y2-y3)*(y2-y3));
if((d1==d2) && (d2==d3))
printf("Given triangle is equilateral");
else if((d1!=d2) && (d2!=d3) && (d1!=d3))
printf("Given triangle is scalene");
else
printf("Given triangle is isosceles but not equilateral");
}
现在,我的问题是如何在运行时将无理数输入作为输入?例如,如果我必须将√3作为输入,那么如何取它,有没有办法在运行时取平方根?
请帮忙。
解决办法是写一段代码询问用户是否要输入无理数,然后在程序内部处理输入。
- 如果第n个顶点包含无理数则打印
- 获取其位置
- 接受整数输入并将其作为无理实体处理
sqrt(integer)
程序内部。
让用户输入平方根内的整数值。
您获取整数值并将其分配为程序内的 sqrt(integer)。
Example ::
如果我想输入一个无理数sqrt(3)
然后你把它作为 int a
并在程序本身内部将其分配为 int b = sqrt( a )
。
我正在用 C 编写代码来查找给定三角形是等边三角形、等腰三角形还是斜角三角形。我把它写成:
#include<stdio.h>
#include<math.h>
int main()
{
float x1,x2,x3,y1,y2,y3;
float d1,d2,d3;
printf("Enter the co-ordinates of 1st vertex: \n");
scanf("%f%f", &x1,&y1);
printf("Enter the co-ordinates of 2nd vertex: \n");
scanf("%f%f", &x2,&y2);
printf("Enter the co-ordinates of 3rd vertex: \n");
scanf("%f%f", &x3,&y3);
d1= sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
d2= sqrt((x1-x3)*(x1-x3) + (y1-y3)*(y1-y3));
d3= sqrt((x2-x3)*(x2-x3) + (y2-y3)*(y2-y3));
if((d1==d2) && (d2==d3))
printf("Given triangle is equilateral");
else if((d1!=d2) && (d2!=d3) && (d1!=d3))
printf("Given triangle is scalene");
else
printf("Given triangle is isosceles but not equilateral");
}
现在,我的问题是如何在运行时将无理数输入作为输入?例如,如果我必须将√3作为输入,那么如何取它,有没有办法在运行时取平方根?
请帮忙。
解决办法是写一段代码询问用户是否要输入无理数,然后在程序内部处理输入。
- 如果第n个顶点包含无理数则打印
- 获取其位置
- 接受整数输入并将其作为无理实体处理
sqrt(integer)
程序内部。
让用户输入平方根内的整数值。 您获取整数值并将其分配为程序内的 sqrt(integer)。
Example ::
如果我想输入一个无理数sqrt(3)
然后你把它作为 int a
并在程序本身内部将其分配为 int b = sqrt( a )
。