首页 > 其他 > 详细

回文数与回文字符串的判断

时间:2016-03-23 06:47:29      阅读:157      评论:0      收藏:0      [点我收藏+]

T:判断一个数是否为回文数

如:121

    12321

    1234321

#include<stdlib.h>
#include<stdio.h>
int main()
{
	int len=0,i=0,j;
	int num=123921;
	int a[10]={0};
	while(num)
	{
		a[i]=num%10;
		num=num/10;
		i++;
	}
	j=i;
	while(j>=i/2)
	{
		if(a[j]!=a[i-j])
		{
			printf("Not!\n");
			system("pause");
			exit(0);
		}
		else
		{
			j--;
		}
	}
	printf("Yes\n");
	system("pause");
	return 0;
}

2.判断一个字符串是否为回文字符串

如:“1234321

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void judge(char *p,int len)
{
	char* star,*end;
	star=p;
	end=p+len-1;
	while(star<end)
	{
		if(*star!=*end)
		{
			printf("Not!\n");
			system("pause");
			exit(0);
		}
		else
		{
			star++;
		    end--;
		}
	}
	printf("Yes!\n");
}
int main()
{
	int LEN=0;
	char arr[]="124321";
	LEN=strlen(arr);
	judge(arr,LEN);
	system("pause");
	return 0;
}


本文出自 “sunshine225” 博客,请务必保留此出处http://10707460.blog.51cto.com/10697460/1754035

回文数与回文字符串的判断

原文:http://10707460.blog.51cto.com/10697460/1754035

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!