欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

abcd ab cd 2c语言,整数趣题(求具有abcd = (ab + cd)^2性质的四位数)

发布时间:2024/3/12 编程问答 96 豆豆
生活随笔 收集整理的这篇文章主要介绍了 abcd ab cd 2c语言,整数趣题(求具有abcd = (ab + cd)^2性质的四位数) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

/****************************************

* File Name : integer.c

* Creat Data : 2015.1.24

* Author : ZY

*****************************************/

/*整数趣题*/

/*求具有abcd = (ab + cd)^2性质的四位数*/

/*3025这个数具有一种独特的性质:将它平分成两段

,即30和25,使之相加后求平方和恰好等于3025本身

求具有这样性质的全部四位数。*/

/*方法一*/

#include

#include

int main()

{

int i,j,m,n;

printf("There are following numbers with 4 digits satisfied condition:\n");

for( i = 1;i < 10;i++ )

{

for( j = 0;j < 10;j++ )

{

for( m = 0;m < 10;m++ )

{

for( n = 0;n < 10;n++ )

{

if((i*1000 + j*100 + m*10 + n )== pow((i*10 + j + m*10 + n),2))

{

printf("%10d",i*1000 + j*100 + m*10 + n);

}

}

}

}

}

printf("\n");

return 0;

}

/*方法二*/

#include

#include

int main()

{

int a[4],i,j,k;

printf("There are following numbers with 4 digits satisfied condition:\n");

for( i = 1000 ;i < 10000;i++ )

{

for( j = 0,k = 10000;k >= 10;j++ )

{

a[j] = (i%k)/(k/10);

k /= 10;

}

if((a[0]*1000 + a[1]*100 + a[2]*10 + a[3]) == pow((a[0]*10+a[1]+a[2]*10+a[3]),2))

{

printf("%10d",a[0]*1000 + a[1]*100 + a[2]*10 + a[3]);

}

}

printf("\n");

return 0;

}

/*方法三*/

#include

int main()

{

int n,a,b;

printf("There are following numbers with 4 digits satisfied condition:\n");

for( n = 1000;n < 10000;n++ )

{

a = n/100;//截取N的前两位存于a

b = n%100;//截取N的后两位存于b

if((a + b)*(a + b) == n)

{

printf("%10d",n);

}

}

printf("\n");

return 0;

}

总结

以上是生活随笔为你收集整理的abcd ab cd 2c语言,整数趣题(求具有abcd = (ab + cd)^2性质的四位数)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。