编程实现:输入直角三角形的两条直角边,求斜边的长度

编程实现:输入直角三角形的两条直角边,求斜边的长度

img


#include<stdio.h>
#include <math.h>
int main()
{
    float a;
    float b;
    float c;
    scanf("%f %f",&a,&b);
    c=pow(pow(a,2)+pow(b,2),0.5);
    printf("%f",c);
    return 0;
}

这是vs2022编译器下的模式,其他编译器可以不要第一行,第一行是因为vs2022只有有这句才能用scanf。

img


x=float(input("请输入直角边a:\n"))
y=float(input("请输入直角边b:\n"))
z=(x*x+y*y)**0.5
print('斜边c的长度为:',z)