小说网 找小说 无限小说 烟雨红尘 幻想小说 酷文学 深夜书屋

基于visual Studio2013解决C语言竞赛题之1026判断排序









题目


解决代码及点评

/************************************************************************/
/* 
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.csdn.net/detail/yincheng01/6681845

解压密码:c.itcast.cn







posted on 2013-12-09 11:49  牛栏山1  阅读(151)  评论(0编辑  收藏  举报

导航