嘿, 我编写了这个可以执行毕达哥拉斯定理的程序。 每次我尝试使其循环时,都会收到一条错误消息,指出嵌套函数已禁用。 你们中的谁能告诉我如何让这个程序循环。谢谢。
这是程序:
#include <stdio.h>
float function (float x, float y);
float function2 (float x, float z);
float function3 (float y, float z);
float main()
{
float x;
float y;
float z;
{
printf("---------------------------------------------------------------");
getchar();
printf("Welcome to right triangle side length calculator");
getchar();
printf("If you do not know the legth of the side, enter 0");
getchar();
printf("Please insert length of the first leg: ");
scanf("%f", &x);
printf("Please insert length of the second leg: ");
scanf("%f", &y);
printf("Please insert length of the hypotenuse: ");
scanf("%f", &z);
}
{
if (z==0){
printf("The length of the hypotenuse is %f\n", function (x, y));}
else if (y==0){
printf("The length of the second leg is %f\n", function2(x, z));}
else if (x==0){
printf("The length of the first leg is %f\n", function3(y, z));}
}
printf(" - A Laszlo Solutions Program -\n");
printf("---------------------------------------------------------------");
getchar();
}
float function(float x, float y) {
return(sqrt(((x*x)+(y*y))));
}
float function2(float x, float z) {
return(sqrt(((z*z)-(x*x))));
}
float function3(float y, float z){
return(sqrt(((z*z)-(y*y))));
}
最佳答案
您需要将function1
、function2
和function3
的定义移到main
之外。
(您的代码不包含循环,无论是嵌套的还是其他形式。我不知道您是否误解了“循环”一词,它指的是重复执行相同的代码。)
关于c - 如何循环勾股定理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5373027/