编程求具有abcd=(ab+cd)²性质的4位数
2017-05-03 22:49
591 查看
题目分析:具有这种性质的四位数没有分布规律,我们可以用穷举法,对所以四位数进行筛选,找出符合条件的四位数。
具体算法实现:任取一个四位数,将它分为前后两部分,前两位为a,后两位为b,然后套用公式进行计算并判断。
运行结果:
具体算法实现:任取一个四位数,将它分为前后两部分,前两位为a,后两位为b,然后套用公式进行计算并判断。
#include <stdio.h> int main() { int n, a, b; printf("There are following numbers with 4 digits satisfied condition:\n"); for (n = 1000; n < 10000; n++) /*四位数取值为1000-9999*/ { a = n / 100; /*取n的前两位存于a中*/ b = n % 100; /*取n的后两位存于b中*/ if ((a + b)*(a + b) == n) /*n为符合条件的四位数时,打印出来*/ { printf("%d\t",n); } } printf("\n"); return 0; }
运行结果:
There are following numbers with 4 digits satisfied condition:2025 3035 9801
相关文章推荐
- 100c之29:求具有abcd= ( ab + cd )^2 性质的四位数
- 1027: 求具有abcd=(ab+cd)2性质的四位数
- 求具有abcd=(ab+cd)2性质的四位数
- 【C语言训练】求具有abcd=(ab+cd)2性质的四位数
- 整数趣题(求具有abcd = (ab + cd)^2性质的四位数)
- 求具有abcd=(ab+cd)2性质的四位数
- 1027:求具有abcd=(ab+cd)^2性质的四位数
- 求具有abcd=(ab+cd)2性质的四位数
- (百例编程)29.求具有abcd=(ab+cd)平方的性质数
- 求具有abcd=(ab+cd)的平方的性质的数
- 求(ab+cd)*(ab+cd)=abcd的四位数
- 左旋字符串例如AABCD旋转一位后为ABCDA,旋转两位为BCDAA
- java中字符串“abcdefgh”转换为“ab:cd:ef:gh”
- 字符串处理:0xABCD,如果是大端规则,在内存中CD存在高地址位,AB存在低位,printf的时候先打CD,再打AB
- 快速求解趣味题 abcd = (ab + cd)^2
- 创建4个线程,4个线程同时对一个文件进行修改。线程1负责向文件写入A,线程2负责向文件写入B,线程3负责写入C,线程4负责写入D。最终文件里的内容应该是ABCDABCDABCD....循环10次;
- 正态分布具有很多好的性质,很多模型假设数据服从正态分布。但是如果数据不服从正态分布怎么办?
- 编程:实现对字符串进行循环右移,例如:输入abcdefgh,循环右移34位,输出ghabcdef
- 编程人员必读书籍推荐-最具有影响力书籍
- 嘻唰唰第六批Problem E: AB编程题--世界杯小组赛