bycj.net
当前位置:首页 >> C语言求勾股数 >>

C语言求勾股数

#include "stdafx.h" int main() { int i; scanf("%d", &i); for(int a = 1; a { for(int b = a; b { for(int c = b; c { if(a*a + b*b == c*c) { printf("%d %d %d\n", a, b, c); } } } } }

for(a=1;a 评论0 0 0

所谓勾股数,就是对于a,b,c,存在a*a+b*b=c*c.为去除重复,可令a 代码如下:int main() { int a,b,c; for(a = 1; a for(b = a;b { int d = a*a+b*b; if(d > 10000) break; for(c = b+1; c { int e; e = c*c; if(e == d) printf("%d,%d,%d\n",a,b,c); if(e>=d) break; } } }

不得不说,楼上两位的算法有疏漏!请看看:k倍的(3,4,5)是否“都能”表示成(m*m-n*n,2*m*n,m*m+n*n)的形式?本人的程序如下:#include <stdio.h>#include <math.h>#define MAX 20000 int gcd(int a,int b) { int t; if(a>b) t=a,a=b,b=t; while(

#include <stdio.h> void main(){ int a,b,c; for(a=2;a<=48;a++) for(b=a+1;b<=49;b++) for(c=b+1;c<=50;c++) if(a*a+b*b==c*c) printf("%-4d%-4d%-4d\n",a,b,c); }

#include<stdio.h>#include<math.h> int main() { void PrintPythNum(unsigned int max); unsigned int n; scanf("%u", &n); if (n < 3) return 0; unsigned int iSquareNum; for (int i = 0;i < n;i++) { iSquareNum = (unsigned int)pow(i + 1, 2); PrintPythNum(

#include int main() {int a,b,c; for(a=1;a<71;a++) for(b=a;b<71;b++) { 权 c=(int)sqrt(a*a+b*b+1); if(c*c==a*a+b*b) printf("%d %d %d\n",a,b,c); } return 0; }

#include "stdafx.h" int main() { int i; scanf("%d", &i); for(int a = 1; a

for x=1:100for y=1:100for z=1:100a=x^2;b=y^2;c=z^2;if a+bcelse print(%io(2),x,y,z)endendendend 本题实际上是求不定方程x 2 +y 2 =z 2 的整数解问题,x,y,z的取值范围都是1到100的整数,可以利用三重循环结构和条件分支结构.

for(a=1;a 评论0 0 0

nmmz.net | rxcr.net | pxlt.net | zhnq.net | tfsf.net | 网站首页 | 网站地图
All rights reserved Powered by www.bycj.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com