日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

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

编程问答

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

發布時間:2024/3/12 编程问答 70 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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性质的四位数)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。