代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
身份证号码验证
作者:
姜南
/ 发布于
2012/2/21
/
756
<div><span class="preprocessor"><span id="1329783584580S" style="display: none;"></span>#include <stdio.h></span></div> <div><span class="preprocessor">#include <string.h></span></div> <div><span class="preprocessor"> </span></div> <div></div> <div><span class="comment">/* 读入数据 */</span><span> </span></div> <div><span class="keyword">void</span><span> input(</span><span class="datatypes">char</span><span> a[]){</span></div> <div><span> </span><span class="datatypes">int</span><span> i; </span></div> <div><span> </span><span class="keyword">for</span><span>(i=0;i<6;i++) scanf(</span><span class="string">"%c"</span><span>,&a[i]);</span></div> <div><span> a[6]=</span><span class="string">'1'</span><span>;</span></div> <div><span> a[7]=</span><span class="string">'9'</span><span>;</span></div> <div><span> </span><span class="keyword">for</span><span>(i=8;i<17;i++) scanf(</span><span class="string">"%c"</span><span>,&a[i]);</span></div> <div><span> a[17]=</span><span class="string">'/0'</span><span>;</span></div> <div><span>}</span></div> <div><span> </span></div> <div></div> <div><span class="comment">/* 计算加权因子 */</span></div> <div><span class="datatypes">int</span><span> mi(</span><span class="datatypes">int</span><span> n){</span></div> <div><span> </span><span class="datatypes">int</span><span> i,sum=1;</span></div> <div><span> </span><span class="keyword">for</span><span>(i=1;i<=n;i++) sum*=2;</span></div> <div><span> sum%=11;</span></div> <div><span> </span><span class="keyword">return</span><span> sum;</span></div> <div><span>}</span></div> <div><span> </span></div> <div></div> <div><span class="comment">/* 计算校验数字 */</span></div> <div><span class="datatypes">int</span><span> jiaoyan(</span><span class="datatypes">char</span><span> a[]){</span></div> <div><span> </span><span class="datatypes">int</span><span> i,sum=0;</span></div> <div><span> </span><span class="keyword">for</span><span>(i=0;i<17;i++)</span></div> <div><span> sum+=mi(17-i)*(a[i]-</span><span class="string">'0'</span><span>);</span></div> <div><span> sum%=11;</span></div> <div><span> </span><span class="keyword">return</span><span> sum;</span></div> <div><span>}</span></div> <div><span> </span></div> <div></div> <div><span class="datatypes">int</span><span> main(){</span></div> <div><span> </span><span class="datatypes">int</span><span> i,n;</span></div> <div><span> </span><span class="datatypes">char</span><span> a[19],f[11]={</span><span class="string">'1'</span><span>,</span><span class="string">'0'</span><span>,</span><span class="string">'X'</span><span>,</span><span class="string">'9'</span><span>,</span><span class="string">'8'</span><span>,</span><span class="string">'7'</span><span>,</span><span class="string">'6'</span><span>,</span><span class="string">'5'</span><span>,</span><span class="string">'4'</span><span>,</span><span class="string">'3'</span><span>,</span><span class="string">'2'</span><span>};</span></div> <div><span> scanf(</span><span class="string">"%d"</span><span>,&n);</span></div> <div><span> </span><span class="keyword">while</span><span>(n--){</span></div> <div><span> getchar();</span></div> <div><span> input(a);</span></div> <div><span> a[17]=f[jiaoyan(a)];</span></div> <div><span> a[18]=</span><span class="string">'/0'</span><span>;</span></div> <div><span> printf(</span><span class="string">"%s/n"</span><span>,a);</span></div> <div><span> }</span></div> <div><span> </span><span class="keyword">return</span><span> 0;</span></div> <div><span>}</span></div> <div></div> <div><span id="1329783584724E" style="display: none;"></span></div>
试试其它关键字
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
姜南
贡献的其它代码
(
7
)
.
搬桌子难题
.
蛇形矩阵
.
格子里的路
.
身份证号码验证
.
歌德巴赫猜想
.
长方体表面积
.
乒乓游戏
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3