在线等编写程序,统计并逐行显示(每行5个数)在区间[10000,50000]上的回文数。

如题所述

你好,程序如下: #include<stdio.h>
void main()
{
int n;
int a,b,c,d,e;
int count;
for(n=10000,count=0;n<=50000;n++)
{
a=n%10;
b=n/10%10;
c=n/100%10;
d=n/1000%10;
e=n/10000;
if(a==e&&b==d)
{
printf("%d\t",n);
count++;
if(0==count%5)
printf("\n");
}
}
} 有疑问提出。望采纳。
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-07-18
#include "stdafx.h"
#include "iostream"
using namespace std;

//判断是否是回文数,是返回1,不是返回-1
int Palindromicity(int input)
{
int i = 0 ;
int Palindromicity=0;
char temp;
char c[100] = {0};
itoa(input,c,10);

for ( i = 0 ; i < strlen(c)/2;i++)
{
if ( c[i] != c[strlen(c)-i-1] )
break;
}
if( i == strlen(c)/2)
return 0;
else
return -1;
}

int _tmain(int argc, _TCHAR* argv[])
{
int count=0,i=0;
for( i = 10000 ; i<50000;i++)
{
if (Palindromicity(i) == 0 )
{
cout<<i<<" ";
count++;
if (count%5 == 0)
cout<<endl;
}
}
getchar();
return 0;
}本回答被网友采纳
相似回答