| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 11945 人关注过本帖
标题:[求助]编程求100以内的所有勾股数
只看楼主 加入收藏
pinglideyu
Rank: 3Rank: 3
来 自:武汉工程大学
等 级:论坛游侠
威 望:1
帖 子:735
专家分:140
注 册:2007-1-7
收藏
得分:0 

#include <stdio.h>
#define N 100

void main()
{
int i,j,k;
int t=0;
printf("打印%d以内所有的勾股数:\n",N);

for (i=1;i<=N;i++)
{
for (j=1;j<=N;j++)
{
for (k=1;k<=N;k++)
{
if ((i*i+j*j==k*k)&&(i<j&&j<k))
printf("%d %d %d\n",i,j,k);
}
}
}


}


~~我的明天我知道~~
2007-03-16 19:56
jiangliangju
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2007-3-9
收藏
得分:0 
The absolute value of x=3 y=4 z=5
The absolute value of x=8 y=6 z=10
The absolute value of x=15 y=8 z=17
The absolute value of x=24 y=10 z=26
The absolute value of x=35 y=12 z=37
The absolute value of x=48 y=14 z=50
The absolute value of x=63 y=16 z=65
The absolute value of x=80 y=18 z=82
The absolute value of x=5 y=12 z=13
The absolute value of x=12 y=16 z=20
The absolute value of x=21 y=20 z=29
The absolute value of x=32 y=24 z=40
The absolute value of x=45 y=28 z=53
The absolute value of x=60 y=32 z=68
The absolute value of x=77 y=36 z=85
The absolute value of x=7 y=24 z=25
The absolute value of x=16 y=30 z=34
The absolute value of x=27 y=36 z=45
The absolute value of x=40 y=42 z=58
The absolute value of x=55 y=48 z=73
The absolute value of x=72 y=54 z=90
The absolute value of x=9 y=40 z=41
The absolute value of x=20 y=48 z=52
The absolute value of x=33 y=56 z=65
The absolute value of x=48 y=64 z=80
The absolute value of x=65 y=72 z=97
The absolute value of x=11 y=60 z=61
The absolute value of x=24 y=70 z=74
The absolute value of x=39 y=80 z=89
The absolute value of x=56 y=90 z=106
The absolute value of x=13 y=84 z=85
The absolute value of x=28 y=96 z=100
The absolute value of x=45 y=108 z=117
33'd:\mplay.com'
请按任意键继续. . .为什么会有117呢,大于100什么意思
2007-03-16 19:58
neverTheSame
Rank: 3Rank: 3
来 自:江西农业大学
等 级:新手上路
威 望:9
帖 子:1511
专家分:0
注 册:2006-11-24
收藏
得分:0 

我的思路是这样的:
勾股数是满足:a的平方+b的平方=c的平方
为了保证不重复,
for(a=1;a<NUM;a++)
for(b=a;b<NUM;b++)
{再验证这三个数能不能成立}
但为了少做一些不必要的循环次数
a最大到 sqrt(2)*(NUM)/2,
for(a=1;a<NUM;a++) 换成for(a=1;a<sqrt(2)*NUM/2;a++)

在做验证这一步时:
先让一个数=sqrt(a的平方+b的平方),
再验证这个数的平方?=a的平方+b的平方;

#include <stdio.h>
#include <conio.h>
#include <math.h>
int check(int,int);
int main(void)
{
int number1,number2,number3;
int control=(int)(sqrt(2)*50);
for(number1=1;number1<control;number1++)
for(number2=number1;number2<100;number2++)
{
number3=check(number1,number2);
if(number3!=0)
printf("%d %d %d \n",number1,number2,number3);
}
getch();
return 0;
}
int check(int num1,int num2)
{
int num3=0;
int sqrtData=num1*num1+num2*num2;
num3=(int)sqrt(sqrtData);
if(num3<100)
{
if(num3*num3==sqrtData)
return num3;
else
return 0;
}
else
return 0;
}


wap酷禾网(http://wap.),提供免费的、优质的、快捷的wap资源下载服务。
2007-03-16 19:59
zhaofeng
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-3-16
收藏
得分:0 

我在优化以下!


MSN:yangzhou_zf@ 寻求C的最高境界
2007-03-16 20:03
lhj2005
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2007-1-23
收藏
得分:0 

谁能加个计数器COUNT,计算下,100以内的勾谷数个数???

2007-03-16 21:13
neverTheSame
Rank: 3Rank: 3
来 自:江西农业大学
等 级:新手上路
威 望:9
帖 子:1511
专家分:0
注 册:2006-11-24
收藏
得分:0 
5 12 13
6 8 10
7 24 25
8 15 17
9 12 15
9 40 41
10 24 26
11 60 61
12 16 20
12 35 37
13 84 85
14 48 50
15 20 25
15 36 39
16 30 34
16 63 65
18 24 30
18 80 82
20 21 29
20 48 52
21 28 35
21 72 75
24 32 40
24 45 51
24 70 74
25 60 65
27 36 45
28 45 53
30 40 50
30 72 78
32 60 68
33 44 55
33 56 65
35 84 91
36 48 60
36 77 85
39 52 65
39 80 89
40 42 58
40 75 85
42 56 70
45 60 75
48 55 73
48 64 80
51 68 85
54 72 90
57 76 95
60 63 87
65 72 97

wap酷禾网(http://wap.),提供免费的、优质的、快捷的wap资源下载服务。
2007-03-16 21:33
zhaofeng
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-3-16
收藏
得分:0 
pinglideyu
能不能把你的55组也贴上来,我想验证一下

MSN:yangzhou_zf@ 寻求C的最高境界
2007-03-16 21:38
喝酸奶的鱼
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2007-3-8
收藏
得分:0 
neverTheSame能不能解释一下为什么“a最大到 sqrt(2)*(NUM)/2”。

学习很重要
2007-03-16 21:53
zhaofeng
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-3-16
收藏
得分:0 

设定3个数 a b c
a*a +b*b= c*c
三个数是不等的
所以a>b或b>a
所以假设a=b

a*a+b*b=c*c
也就是 a*a+a*a=c*c 同理c*c =num
2*a*a =num
a=sqrt(mun/2)


MSN:yangzhou_zf@ 寻求C的最高境界
2007-03-16 22:04
flmls
Rank: 1
等 级:新手上路
帖 子:64
专家分:0
注 册:2007-2-6
收藏
得分:0 
谁会设置一个计数器啊,

放在程序中,效果是最后计算出 一共有几个符合条件的 勾古
2007-03-16 22:56
快速回复:[求助]编程求100以内的所有勾股数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021556 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved