小小程序

来源:互联网 发布:网站源码下载器 编辑:程序博客网 时间:2024/06/10 01:21

#include<stdio.h>
#include<stdlib.h>
main()
{
 int i=0;
 int num_weishu;
 int number;
 int number_switch;
 int *p=NULL;
 int j;
 printf("input a number ");
 scanf("%d",&number);
    num_weishu= number;
 while(num_weishu!=0)
 {
      num_weishu = num_weishu/10;
   i++;
 }
 p=(int *)malloc(i*sizeof(int));
 if(p==NULL)
    {
     printf("error");
  return 0;
 }
    number_switch = number;

 for(j=0;j<i;j++)
 {
  p[j] = number_switch%10;
  number_switch = number_switch/10;
  //printf("%d",p[j]);
 }

 for( j=0; j<i/2;j++)
 {
  if( p[j] != p[i-j-1] ) break;
 }
    if(j==i/2)
 {
  printf("number is huiwenshu");
 }
 else printf("number is not huiwenshu");
    free(p);
}

原创粉丝点击