C 语言实例 - 判断回文数
C 语言教程
· 2019-02-20 20:28:16
判断一个数是否为回文数。
设n是一任意自然数。若将n的各位数字反向排列所得自然数n1与n相等,则称n为一回文数。例如,若n=1234321,则称n为一回文数;但若n=1234567,则n不是回文数
实例
#include <stdio.h>
int main()
{
int n, reversedInteger = 0, remainder, originalInteger;
printf("输入一个整数: ");
scanf("%d", &n);
originalInteger = n;
// 翻转
while( n!=0 )
{
remainder = n%10;
reversedInteger = reversedInteger*10 + remainder;
n /= 10;
}
// 判断
if (originalInteger == reversedInteger)
printf("%d 是回文数。", originalInteger);
else
printf("%d 不是回文数。", originalInteger);
return 0;
}
运行结果:
输入一个整数: 12321 12321 是回文数
点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html
Is Parallel Programming Hard, And, If So, What Can You Do About
Paul E. McKenney
The purpose of this book is to help you understand how to program shared-memory parallel machines without risking your sanity.1 By describing the algorithms and designs that have worked well in the pa......一起来看看 《Is Parallel Programming Hard, And, If So, What Can You Do About 》 这本书的介绍吧!