我做的三角形找到perameters此代碼爲直角三角形 但輸出似乎出來的權利,但反覆我的代碼輸出重複
#include<iostream>
#include<vector>
#include<list>
#include <math.h>
#include <algorithm>
using namespace std;
int main()
{
int a;
float c;
vector<double> retval;
double intiger;
double p;
double l = 25;
float array[3];
for (int b=1; b < l; b++) {
for (int a=1; a < l; a++) {
intiger = sqrt((b*b)+(a*a));
c = sqrt((b*b)+(a*a));
if (c == intiger) {
array[0]=a;
array[1]=b;
array[2]=c;
//int elements = sizeof(array);
//cout << elements << endl;
sort(array, array +3);
//retval.push_back(a);
//retval.push_back(b);
//retval.push_back(c);
if (c == a) {
continue;
}
p = a + b + c;
if (p > l) {
break;
}
//cout << "p == " << p << endl;
} else {
continue;
}
//if (retval.size()== 62)
//cout << c <<endl;
//cout << " a = " << a << " b = " << b << " c = " << c << " "
cout << array[0] << " " << array[1] << " " << array[2] << endl;
}
}
return 0;
}
輸出出來要重複兩次。
3 4 5
3 4 5
6 8 10
6 8 10
我想讓它重複一次。
請您縮進碼。 – 2012-03-11 02:48:05
將「cout」向下移動1行,在}之後。 – TreyA 2012-03-11 02:48:16
我移動了cout,但代碼出來了,但它仍然重複 – user1261771 2012-03-11 02:54:57