Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
switch.c
Package: C语言精彩编程百例_源代码.rar [view]
Upload User: bjtelijie
Upload Date: 2010-01-01
Package Size: 87k
Code Size: 2k
Category:
Algorithm
Development Platform:
Visual C++
- # include <stdio.h>
- void main()
- {
- int num;
- /* 下面定义的各变量,分别代表个位,十位,百位,千位,万位,十万位以及位数 */
- int indiv, ten, hundred, thousand;
- int ten_thousand, hundred_thousand, place;
- printf("请输入一个整数(0~999999):");
- scanf("%d", &num);
- /* 判断变量num的位数 */
- if(num > 99999)
- place = 6;
- else if(num > 9999)
- place = 5;
- else if(num > 999)
- place = 4;
- else if(num > 99)
- place = 3;
- else if(num > 9)
- place = 2;
- else
- place = 1;
- printf("place = %dn", place);
- printf("每位数字为:");
- /* 求出num在各位上的值 */
- hundred_thousand = num/100000;
- ten_thousand = (num - hundred_thousand*100000)/10000;
- thousand = (num - hundred_thousand*100000 - ten_thousand*10000)/1000;
- hundred = (num - hundred_thousand*100000 - ten_thousand*10000
- - thousand*1000)/100;
- ten = (num - hundred_thousand*100000 - ten_thousand*10000
- - thousand*1000 - hundred*100)/10;
- indiv = num - hundred_thousand*100000 - ten_thousand*10000
- - thousand*1000 - hundred*100 - ten*10;
- /* 判断变量num的位数,并根据位数做出相应的输出 */
- switch(place)
- {
- case 1: printf("%d", indiv);
- printf("n反序数字为:");
- printf("%dn", indiv);
- break;
- case 2: printf("%d, %d", ten, indiv);
- printf("n反序数字为:");
- printf("%d%dn", indiv, ten);
- break;
- case 3: printf("%d, %d, %d", hundred, ten, indiv);
- printf("n反序数字为:");
- printf("%d%d%dn", indiv, ten, hundred);
- break;
- case 4: printf("%d, %d, %d, %d", thousand, hundred, ten, indiv);
- printf("n反序数字为:");
- printf("%d%d%d%dn", indiv, ten, hundred, thousand);
- break;
- case 5: printf("%d, %d, %d, %d, %d", ten_thousand, thousand,
- hundred, ten, indiv);
- printf("n反序数字为:");
- printf("%d%d%d%d%dn", indiv, ten, hundred,
- thousand, ten_thousand);
- break;
- case 6: printf("%d, %d, %d, %d, %d, %d", hundred_thousand,
- ten_thousand, thousand, hundred, ten, indiv);
- printf("n反序数字为:");
- printf("%d%d%d%d%d%dn", indiv, ten, hundred, thousand,
- ten_thousand, hundred_thousand);
- break;
- default: printf("Not find.n");
- break;
- }
- }