发信人: stonepeter (笨笨石头.NET中尉), 信区: Math
标 题: 合条件的回文数
发信站: BBS 一网情深站 (Thu Apr 11 13:36:52 2002), 转信
///filename: HuiWen.CS
//////M是11到999之间的数,如果M^2和M^3均为回文数,就称之为“合条件的回文数”
,并打印输出////////
///Programmed By stonepeter 2002/04/11
///Windows XP
///Visual C#.NET
///
///运行结果
///11是合条件的回文数,121,1331
///101是合条件的回文数,10201,1030301
///111是合条件的回文数,12321,1367631
///
using System;
class Huiwen
{
public static bool IntIsHuiWen(int number)
{
int i;
string s = number.ToString(); //将数字转化为字符串
//字符串从左、右同时取看是否相等
for( i=0; i < s.Length/2 ; i++)
{
if( s[i] != s[s.Length-i-1] )
return false;
}
return true;
}
public static void Main(string[] args)
{
int i;
for( i=11; i <=999; i++ )
{
if( IntIsHuiWen(i*i) && IntIsHuiWen(i*i*i) )
Console.WriteLine( "{0}是合条件的回文数,{1},{2}", i, i*i, i*i*i );
}
}
}
标 题: 合条件的回文数
发信站: BBS 一网情深站 (Thu Apr 11 13:36:52 2002), 转信
///filename: HuiWen.CS
//////M是11到999之间的数,如果M^2和M^3均为回文数,就称之为“合条件的回文数”
,并打印输出////////
///Programmed By stonepeter 2002/04/11
///Windows XP
///Visual C#.NET
///
///运行结果
///11是合条件的回文数,121,1331
///101是合条件的回文数,10201,1030301
///111是合条件的回文数,12321,1367631
///
using System;
class Huiwen
{
public static bool IntIsHuiWen(int number)
{
int i;
string s = number.ToString(); //将数字转化为字符串
//字符串从左、右同时取看是否相等
for( i=0; i < s.Length/2 ; i++)
{
if( s[i] != s[s.Length-i-1] )
return false;
}
return true;
}
public static void Main(string[] args)
{
int i;
for( i=11; i <=999; i++ )
{
if( IntIsHuiWen(i*i) && IntIsHuiWen(i*i*i) )
Console.WriteLine( "{0}是合条件的回文数,{1},{2}", i, i*i, i*i*i );
}
}
}
浙公网安备 33010602011771号