Menu Close

C语言练习:检查两个整数之间的回文数并打印出来

#include<stdio.h>
int main(){
   int num, rem, reverse_num, temp, start, end;

   printf("Enter the lower limit: ");
   scanf("%d",&start);

   printf("Enter the upper limit: ");
   scanf("%d",&end);

   printf("Palindrome numbers between %d and %d are: ",start,end);
   for(num=start;num<=end;num++){
      temp=num;
      reverse_num=0;
      while(temp){
         rem=temp%10;
         temp=temp/10;
         reverse_num=reverse_num*10+rem;
      }
      if(num==reverse_num)
         printf("%d ",num);
   }
   return 0;
}

结果

Enter the lower limit: 12
Enter the upper limit: 128
Palindrome numbers between 12 and 128 are: 22 33 44 55 66 77 88 99 101 111 121
Process returned 0 (0x0) execution time : 18.003 s
Press any key to continue.
READ  C语言练习:输入一个字符,输出其ASCII码
除教程外,本网站大部分文章来自互联网,如果有内容冒犯到你,请联系我们删除!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

Leave the field below empty!

Posted in C 决策和循环语句

Related Posts