C 练习实例30 - 回文数
C 语言教程
· 2019-02-21 19:29:36
题目:一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。
程序分析:学会分解出每一位数。
程序源代码:
实例
// Created by www.codercto.com on 15/11/9.
// Copyright © 2015年 码农教程. All rights reserved.
//
#include <stdio.h>
int main( )
{
long ge,shi,qian,wan,x;
printf("请输入 5 位数字:");
scanf("%ld",&x);
wan=x/10000; /*分解出万位*/
qian=x%10000/1000; /*分解出千位*/
shi=x%100/10; /*分解出十位*/
ge=x%10; /*分解出个位*/
if (ge==wan&&shi==qian) { /*个位等于万位并且十位等于千位*/
printf("这是回文数\n");
} else {
printf("这不是回文数\n");
}
}
以上实例输出结果为:
请输入 5 位数字:12321 这是回文数 请输入 5 位数字:12345 这不是回文数
点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html
Machine Learning in Action
Peter Harrington / Manning Publications / 2012-4-19 / GBP 29.99
It's been said that data is the new "dirt"—the raw material from which and on which you build the structures of the modern world. And like dirt, data can seem like a limitless, undifferentiated mass. ......一起来看看 《Machine Learning in Action》 这本书的介绍吧!