c - 如何确定一组三角形中角最小的三角形

标签 c

我一直在尝试创建一个程序来确定: 当给定一组具有最小角度的直角三角形时。 但我遇到了很多困难,我推断如果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;

最佳答案

如果这是您的完整源代码,则某些部分会丢失。您可以导入<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;
}

关于c - 如何确定一组三角形中角最小的三角形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19479094/

相关文章:

在 C 中不使用库函数将 int 转换为字符串?

c - 使用 C 套接字发送带有 VLAN 标记的数据包

c - 从命令提示符运行 Hello World C 代码?

c - "knowledge is power"c语言谜题

c - 指针指向指针,值不更新

c - GPIO 输出状态如何在进程退出时保持不变?

c++ - 如何从一系列快照中编码视频?

c - 如何从 C 语言的 pcap 获取网络层和传输层协议(protocol)?

c - c中的可用内存问题删除了链表中的某些值

c - 文本的最大大小是否包含空(停止)字符