信息:a是直角三角形最短腿的长度,b是另一条腿的长度,a和b的差值越大,角度越小。这就是:
因此,最小的角度是在三重(5,12,13)。
我正在编写一个程序,比较定义在一个范围内的所有毕达哥拉斯三元组,并以最小的角度打印这个三元组。到目前为止,我所拥有的是不起作用的,我也不知道我能从这里走到哪里。
#include <stdio.h>
int smallest(int a, int b) {
int difference = b - a;
return 0;
}
int main() {
int a = 0, b = 0, c = 0, n, counter = 1, i = 0;
printf("Please Enter a Positive Integer: \n");
scanf("%d", &n);
for (c = 0; c < n; c++) {
for (b = 0; b < c; b++) {
for (a = 0; a < b; a++) {
if (a * a + b * b == c * c ) {
printf("%d:\t%d %d %d\n", counter++, a, b, c);
}
}
}
i = counter - 1;
}
printf ("The difference is %d\n", smallest(a, b));
printf ("There are %d Pythagorean Triples in this range.\n", i);
return 0;
}程序刚刚打印出的差是0
我正在寻找要打印的程序,上面的例子是“最小角的三角形是(5,12,13)”。
我知道我必须对这些差异进行分类和比较,但到目前为止,我只知道这些,有什么建议吗?
发布于 2013-10-23 07:38:40
发布于 2013-10-23 07:45:18
您的smallest-code在每种情况下都返回0。您确定不想返回difference (甚至b-a)吗?
int smallest(int a, int b) {
return b-a;
}https://stackoverflow.com/questions/19530872
复制相似问题