C语言:输入数值N,求N内所有勾股数
C语言:输入数值N,求N内所有勾股数,最后printf所有勾股数的数量,这些组勾股数的数值,和最大一组勾股数的值,顺序不能改变试成功之后还可以加赏,急急急急急急急急急...
C语言:输入数值N,求N内所有勾股数,最后printf所有勾股数的数量,这些组勾股数的数值,和最大一组勾股数的值,顺序不能改变
试成功之后还可以加赏,急急急急急急急急急 展开
试成功之后还可以加赏,急急急急急急急急急 展开
2个回答
展开全部
#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(iSquareNum);
}
return 0;
}
int isSquareNum(unsigned int num)//判断是否是平方数
{
double result = sqrt((double)num);
if ((int)result == result)
return 1;
return 0;
}
void PrintPythNum(unsigned int max)//判断是否是勾股数,并且打印
{
int isSquareNum(unsigned int num);
unsigned int min=1, mid,i=2;
static int count = 0;
while(min < max / 2)
{
mid = max - min;
if (isSquareNum(mid)) {
count++;
printf("NO.%d : %u^2+%u^2=%u^2\n",count,(int)sqrt(min), (int)sqrt(mid), (int)sqrt(max));
}
min = (unsigned int)pow(i, 2);
i++;
}
}
#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(iSquareNum);
}
return 0;
}
int isSquareNum(unsigned int num)//判断是否是平方数
{
double result = sqrt((double)num);
if ((int)result == result)
return 1;
return 0;
}
void PrintPythNum(unsigned int max)//判断是否是勾股数,并且打印
{
int isSquareNum(unsigned int num);
unsigned int min=1, mid,i=2;
static int count = 0;
while(min < max / 2)
{
mid = max - min;
if (isSquareNum(mid)) {
count++;
printf("NO.%d : %u^2+%u^2=%u^2\n",count,(int)sqrt(min), (int)sqrt(mid), (int)sqrt(max));
}
min = (unsigned int)pow(i, 2);
i++;
}
}
2015-10-20
展开全部
没时间限制的话:
#include<stdio.h>
int main()
{
int n;
while(scanf("%d",&n){
for(int i=1;i<=n;++i)
for(int j=i+1;j<=m;++j)
for(int k=j+1;k<=n;++k)
if(i*i+j*j==k*k) printf("%d,%d,%d\n",i,j,k);
}
return 0;
}
#include<stdio.h>
int main()
{
int n;
while(scanf("%d",&n){
for(int i=1;i<=n;++i)
for(int j=i+1;j<=m;++j)
for(int k=j+1;k<=n;++k)
if(i*i+j*j==k*k) printf("%d,%d,%d\n",i,j,k);
}
return 0;
}
更多追问追答
追问
还有在范围N内所有勾股数的数量和范围内最大的一组勾股数呢?
追答
#include
int main()
{
int n;
while(scanf("%d",&n)){
int x,y,z,count=0;
for(int i=1;i<=n;++i)
for(int j=i+1;j<=n;++j)
for(int k=j+1;k<=n;++k)
if(i*i+j*j==k*k) {
printf("%d,%d,%d\n",i,j,k);
count++;
x=i,y=j,z=k;
}
printf("total number: %d\n",count);
printf("max: %d,%d,%d\n",x,y,z);
}
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询