c - 如何循环勾股定理程序?

标签 c loops

嘿, 我编写了这个可以执行毕达哥拉斯定理的程序。 每次我尝试使其循环时,都会收到一条错误消息,指出嵌套函数已禁用。 你们中的谁能告诉我如何让这个程序循环。谢谢。

这是程序:

#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))));

    }

最佳答案

您需要将function1function2function3的定义移到main之外。

(您的代码不包含循环,无论是嵌套的还是其他形式。我不知道您是否误解了“循环”一词,它指的是重复执行相同的代码。)

关于c - 如何循环勾股定理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5373027/

相关文章:

python - 循环遍历数据框(列和行)并替换数据

arrays - 具有变量转换的多元回归自动化

javascript - nodejs 中类似 c 的互斥量

字谜 C 程序如何(忽略大写字母)

c - 在 C 中将方阵提高到 N 次方

c - 如何并发运行非线程安全的代码?

c - 链表打印问题结构

function - Julia 在循环打印消息之前等待函数完成

php - 递归地倍数 foreach 或 RecursiveIteratorIterator

java - 嵌套循环在 Mastermind 游戏中无法正常工作