输出三边在500以内的能构成直角三角形的数列
2017-05-24 19:13
337 查看
#include<iostream> #include<cstring> using namespace std; //判断是否是直角三角形 bool isHardTriangle(int side1,int side2,int hypotenuse); int main() { struct Triangle { int side1; int side2; int hypotenuse; int flag;//决定该条数据是否显示 1为显示 0不显示 }; Triangle arr[500]; int counter=0; for(int side1=3;side1<=500;side1++) { for(int side2=4;side2<=500;side2++) { for(int hypotenuse=5;hypotenuse<=500;hypotenuse++) { if(isHardTriangle(side1,side2,hypotenuse)) { cout<<side1<<"\t"<<side2<<"\t"<<hypotenuse<<endl; arr[counter].side1=side1; arr[counter].side2=side2; arr[counter].hypotenuse=hypotenuse; arr[counter].flag=1; counter++; } } } } cout<<endl<<endl; return 0; } bool isHardTriangle(int side1,int side2,int hypotenuse) { bool isHardTriangle=false; if(side1*side1+side2*side2==hypotenuse*hypotenuse) { isHardTriangle=true; } return isHardTriangle; }
运行效果如下
显然,这是有不足之处的。
如,{5,12,13},{12,5,13}表示的是同一个三角形。最佳的输出效果是不输出这些相同的序列。
相关文章推荐
- 控制台输入三条边长,判断是否能构成三角形。如果能构成,输出三角形的周长,并且告知该三角形是什么类型(锐角、直角、钝角),再判断下该三角形是 等腰、等边还是不等边三角形。
- 数字问题,找500以内的直角三角形的边
- 判断三个边能否构成三角形,并判断能够成什么三角形(锐角、钝角、直角)
- 编写程序实现求1~500以内的所有素数,同时指定每行输出5个素数。(C++)
- 任意输入三条边(a,b,c实型),若能构成三角形,则计算并输出其面积,否则输出标志“No Triangle!”。
- 判断能否构成三角形 并输出三角形的周长和面积
- Problem C: 上直角三角形输出
- 输入三个点的坐标,实现判断此三角形是不是直角三角形,并输出此三角形的周长。
- C语言:输出n行由大写字母A开始构成的三角形字符阵列。
- if else 应用之经典例题判断能否构成三角形并输出面积
- 在JavaScript中用for循环输出等腰、直角三角形、菱形
- C语言考试题--星号直角三角形输出求解
- 求100以内的直角三角形的组合
- 上直角三角形输出
- 简单编程(十一)简单编程 判断并输出500以内既能够被3整除又能够被6整除的整数。
- 通过循环输出倒直角三角形以及等边三角形
- JavaScript是否构成直角三角形-斜边长度的平方等于其他两条边长的平方和
- 输入三角形a,b,c的值判断其能否构成三角形并输出三角形的性质
- C++上机报告,任意输入三条边(a,b,c实型),若能构成三角形,则计算并输出其面积,否则输出标No Triangle!
- 定义一个函数,判断三个整形边长能否构成三角形,如果是三角形,则判断它是否是直角三角形。