| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 435 人关注过本帖
标题:[求助]我的程序为什么达不到效果??
只看楼主 加入收藏
wongkin
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2005-6-3
收藏
 问题点数:0 回复次数:0 
[求助]我的程序为什么达不到效果??
Statement of the Problem

We say that a number is a palindrom if it is the sane when read from left to right or from right to left. For example, the number 75457 is a palindrom.

Of course, the property depends on the basis in which is number is represented. The number 17 is not a palindrom in base 10, but its representation in base 2 (10001) is a palindrom.

The objective of this problem is to verify if a set of given numbers are palindroms in any basis from 2 to 16.

Input Format

Several integer numbers comprise the input. Each number 0 < n < 50000 is given in decimal basis in a separate line. The input ends with a zero.

Output Format

Your program must print the message Number i is palindrom in basis where I is the given number, followed by the basis where the representation of the number is a palindrom. If the number is not a palindrom in any basis between 2 and 16, your program must print the message Number i is not palindrom.

Sample Input

17
19
0

Sample Output

Number 17 is palindrom in basis 2 4 16
Number 19 is not a palindrom
以上的是题目,要求判断一个数他的从2到16进制是否是头尾相等的数?
我的程序:
#include <stdio.h>
int fac(int x,int y)
{
int i,a[50],b[50],count=0;
for(i=0,a[0]=x;a[i]==0;i++)
{
a[i+1]=a[i]/y;
b[i]=a[i]%y;
++count;
}
if(count%2==0)
{
for(i=0;i<(int)(1+count)/2-1;i++,count--)
{
if(b[i]=b[count]) return 1;
}
}
if(count%2!=0)
{
for(i=0;i<(int)(1+count)/2;i++,count--)
{
if(b[i]=b[count]) return 1;
}
}
}
main()
{
int n,i,flag=1,flag2=1;
while(flag==1)
{
scanf("%d",&n);
if(n!=0)
{
printf("number %d is ",n);
for(i=2;i<=16;i++)
{
if(fac(n,i)) flag2=0;
else flag2=1;
}
if(flag2==1)
{
printf("palindrom in basis ");
{
for(i=2;i<=16;i++) {printf("%d ",i);}
}
}
if(flag2==0) printf("not a palindrom\n");
}else flag=0;
}
}
运行达不到效果,我知道我的程序写的很是不好,只是初步的~~
请教各位~~了
我运行总是输出“number X is not a palindrom",X 为不输入的数字,为什么呢?

搜索更多相关主题的帖子: 效果 
2006-02-26 12:47
快速回复:[求助]我的程序为什么达不到效果??
数据加载中...
 
   



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

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