-1

我一直在尝试创建一个程序来确定:当给定一组具有最小角度的直角三角形时。但是我遇到了很多困难我已经推断出如果a是边长并且b和c是斜边是a

float a, b, c, a1, b1, c1;
float sinTheta, sinTheta1;

printf ("Please enter values for a, b, c\n");
scanf ("%f%f%f", &a, &b, &c);

printf ("Please enter values for a1, b1, c1\n");
scanf ("%f%f%f", &a1, &b1, &c1);


sinTheta=a/c;
sinTheta1=a1/c1;

if (sinTheta < sinTheta1)
    printf ("the triangle a b c has the smaller angle\n");

    else
        if (sinTheta > sinTheta1)
            printf ("The triangle a1, b1, c1 has the smaller angle\n");

return 0;
4

1 回答 1

1

如果这是您的完整源代码,则缺少某些部分。<stdio.h>您可以通过写入导入

#include <stdio.h>

在代码的开头。

此外,没有main() { ... }. 您也可以处理两个角度相等的情况sinTheta == sinTheta1

#include <stdio.h>

int main() {

float a, b, c, a1, b1, c1;
float sinTheta, sinTheta1;

printf ("Please enter values for a, b, c\n");
scanf ("%f%f%f", &a, &b, &c);

printf ("Please enter values for a1, b1, c1\n");
scanf ("%f%f%f", &a1, &b1, &c1);


sinTheta=a/c;
sinTheta1=a1/c1;

if (sinTheta < sinTheta1) {
    printf ("the triangle a b c has the smaller angle\n");
}
else if (sinTheta > sinTheta1) {
     printf ("The triangle a1, b1, c1 has the smaller angle\n");
}
else 
{
    printf ("the angles are the same\n");
}
return 0;
}

顺便说一句: 的值b是多余的。

编辑:

快速而肮脏的方法:

#include <stdio.h>

int main() {

float a, c;
float sinTheta;

float sinThetaMin;
int nMin;
int nTriangle=2;  // specifies the number of triangles
int i;


for (i=0; i<nTriangle; i++) {
    printf ("Please enter values for a, c for triangle %d\n", i+1);
    scanf ("%f%f", &a, &c);
    sinTheta = a/c;
    printf("%f\n", sinTheta);
    if (i == 0) {
        sinThetaMin = sinTheta;
        nMin = i+1;
    }
    else {
        if (sinTheta < sinThetaMin) {
                sinThetaMin = sinTheta;
                nMin = i+1;
        }
    }

}

printf("Smallest triangle is number %d with a/c = %f\n", nMin, sinThetaMin);

return 0;
}
于 2013-10-20T15:49:10.650 回答