题目
解决代码及点评
/************************************************************************/
/*
26. 把一个偶数位的数从当中分开成为两个数,这两个数的和的平方等于原数。
如(8+1)2=81,(20+25)2=2025。求10至9999之间满足这样条件的数是哪些? 共有多少个?
*/
/************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
//返回数字位数
int GWS26(int num)
{
int count=0;
while(num)
{
count++;
num/=10;
}
return count;
}
bool IsSpecal26(int num)
{
if (GWS26(num)%2)
{
return false;
}
else
{
int temp=1;
for (int i=0;i<GWS26(num)/2;i++)
{
temp*=10;
}
if (num==(num%temp+num/temp)*(num%temp+num/temp))
{
return true;
}
else
return false;
}
}
void main()
{
int num=0;
for (int i=10;i<=9999;i++)
{
if (IsSpecal26(i))
{
printf("%5d",i);
num++;
}
}
printf("\n这些数字共有%d",num);
system("pause");
}
代码编译以及运行
由于资源上传太多,资源频道经常被锁定无法上传资源,同学们可以打开VS2013自己创建工程,步骤如下:
1)新建工程
2)选择工程
3)创建完工程如下图:
4)增加文件,右键点击项目
5)在弹出菜单里做以下选择
6)添加文件
7)拷贝代码与运行
程序运行结果
代码下载
http://download.****.net/detail/yincheng01/6681845
解压密码:c.itcast.cn