- static void Main(string[] args)
- {
- int zhi1,zhi2;
- double xie3;
- for (zhi1 = 3; zhi1 <100; zhi1++)
- {
- for (zhi2 = 4; zhi2 <100; zhi2++)
- {
-
- xie3 =Math.Sqrt(zhi1*zhi1+zhi2*zhi2);
- if (xie3 <= 100)
- {
- if (xie3 - Math.Truncate(xie3) == 0)//判断是不是整数,不是整数就不要了
- {
- if (sanjiaoxing(zhi1, zhi2, Convert.ToInt32(Math.Truncate(xie3))))
- {
- Console.WriteLine("勾股数为:{0},{1},{2}", zhi1, zhi2, xie3);
- }
- }
- }
-
- }
- }
- Console.ReadKey();
- }
- public static bool sanjiaoxing(int bian1, int bian2, int bian3)//成为三角形的判断条件,返回值为bool
- {
- bool zhisanjiaoxing;
- if(bian1+bian2>bian3)
- {
- if (bian3 - bian2 < bian1)
- {
- if (bian3 > bian1 && bian3 > bian2)
- {
- zhisanjiaoxing = true;
- }
- else
- {
- zhisanjiaoxing = false;
- }
- }
- else
- {
- zhisanjiaoxing = false;
- }
- }
- else
- {
- zhisanjiaoxing=false;
- }
- return zhisanjiaoxing;
- }
- }
复制代码 这个我写的也调试了可以,可以希望你帮到你! |