| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 404 人关注过本帖
标题:求助,此程序无法运行,请查找错误
只看楼主 加入收藏
ashencs
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-6-26
收藏
 问题点数:0 回复次数:2 
求助,此程序无法运行,请查找错误

// Main.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "math.h"
#include "ostream.h"

// Get the minor number between "a" and "b".
#define min(a,b) (((a) < (b)) ? (a) : (b))

// Eliminate some special impossible number.
bool IsImpossibleNum(int iNumByPos0, int iNumByPos1, int iNumByPos2)
{
if (0 == iNumByPos0 || 1 == iNumByPos0 || 5 == iNumByPos0 || 6 == iNumByPos0 || 0 == iNumByPos1 || 0 == iNumByPos2)
{ // Because these number's square include themselves, e.g. "5 * 5 = 25"
return true;
}

// Get the "iNumByPos0"'s square's lowest position's number
int i = (iNumByPos0 * iNumByPos0) % 10;

if (i == iNumByPos0 || i == iNumByPos1 || i == iNumByPos2)
{ // Then it's impossible.
return true;
}

return false;
}

void NumCheck(int Num, int NumEnd)
{
bool bIsImpossible = false;
int NumByPos[9] = { 0 }, j = 0, k = 0, NumSquare = 0, divNum = 0;

for (; Num < NumEnd; Num++)
{
// Fill the number array by position.
j = 0;
NumByPos[j++] = Num / 100;
NumByPos[j++] = (Num % 100) / 10;
NumByPos[j++] = Num % 10;
bIsImpossible = IsImpossibleNum(NumByPos[j-1], NumByPos[j-2], NumByPos[j-3]);
if (!bIsImpossible)
{
NumSquare = Num * Num; // get it's square.
divNum = 100000; // the divider

// Fill the number array by position.
for (; (!bIsImpossible) && (j < 9); j++)
{
NumByPos[j] = NumSquare / divNum; // every position's number
if (0 == NumByPos[j])
{ // If it has "0", then it's impossible.
bIsImpossible = true;
break;
}
NumSquare %= divNum;
divNum /= 10;
}

// Check the number array by position.
for (j = 0; (!bIsImpossible) && (j < 9 - 1); j++)
{ // check "x != y"
for (k = j + 1; k < 9; k++)
{
if (NumByPos[j] == NumByPos[k])
{ // If it has two equal number, then it's impossible.
bIsImpossible = true;
break;
}
}
}

if (!bIsImpossible)
{ // It's the needed number.
cout << Num << "\'s square is " << Num * Num << endl;
}
}
}
}

int main(int argc, char* argv[])
{
int Num = (int)sqrt(100000L); // the minimum
int NumEnd = min((int)sqrt(1000000L), 999); // the maximum

// Check the needed number between "Num" and "NumEnd".
NumCheck(Num, NumEnd);

// Remind the user to quit.
cout << "Press anykey to quit." << flush;

// Pause the program
getchar();

return 0;
}


搜索更多相关主题的帖子: 运行 
2007-06-29 19:11
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
收藏
得分:0 
计算平方根的啊? ..
帮你编译了一下(WinXP SP2 + VC6)
问题:
1. stdafx.h头文件不是必须的
2. 最后的getchar()函数是stdio.h库中的函数, 你没有包含这个头文件.

你似乎对C++了解不是很多啊..

女侠,约吗?
2007-06-29 19:39
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
收藏
得分:0 
#include <cmath>
#include <iostream>
using namespace std;

使用标准头文件。

Fight  to win  or  die...
2007-06-29 19:44
快速回复:求助,此程序无法运行,请查找错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020526 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved