当前位置:网站首页>C语言经典例题-商品检验码
C语言经典例题-商品检验码
2022-07-23 10:47:00 【Blue_lan18】

数字013800 15173 5出现在条形码的下方。第1个数字表示商品的种类(大部分商品用o或者7表示,2表示需要称量的商品,3表示药品或与健康相关的商品,而5表示赠品)。第一组5位数字用来标识生产商(13800是雀巢美国的冰冻食品公司的代码)。第二组5位数字用来标识产品(包括包装尺寸)。最后一位数字是“校验位”,它唯一的目的是用来帮助识别前面数字中的错误。如果条形码扫描出现错误,那么前11位数字可能会和最后一位数字不匹配,超市扫描机将拒绝整个条形码。
下面是一种计算校验位的方法:首先把第1位、第3位、第5位、第7位、第9位和第11位数字
相加;然后把第2位、第4位、第6位、第8位和第10位数字相加;接看把弟一次加法的络宋来以,再和第二次加法的结果相加;随后再把上述结果减去1;相减后的结果除以10取余数;最后用9
减去上一步骤中得到的余数。
# include <stdio.h>
int main()
{
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11;
int firstResult = 0, secondResult = 0, thirdResult = 0, fourResult = 0;//fourResult即为检验码
printf("Please enter 11 numbers: ");
scanf("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d", &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11);
firstResult = a1 + a3 + a5 + a7 + a9 + a11;
secondResult = a2 + a4 + a6 + a8 + a10;
thirdResult = 3 * firstResult + secondResult;
fourResult = 9 - (thirdResult - 1) % 10;
printf("a11 = %d\n", fourResult);
return 0;
}
边栏推荐
- 基于matlab的BOC调制解调的同步性能仿真,输出跟踪曲线以及不同超前滞后码距下的鉴别曲线
- 安全7.18作业
- postgresql没有nvl的解决办法,postgresql查询所有的表
- Completely uninstall MySQL in centos7
- Exploration and practice of Ali multimodal knowledge atlas
- Liunx:浅析vim编辑器基本使用
- Multiple backpacks!
- 338. Bit count
- Simulation de modulation et de démodulation du signal CBOC basée sur MATLAB, sortie de corrélation, spectre de puissance et suivi de décalage de fréquence
- BGP basic configuration
猜你喜欢
随机推荐
The problem of double type precision loss and its solution
Clickhouse, let the query fly!!!
ClickHouse,让查询飞起来!!!
信号量
BGP routing principle
The current situation and history of it migrant workers
What is the difference between server hosting and virtual host
airserver在哪里下载?使用方法教程
PostgreSQL has no NVL solution. PostgreSQL queries all tables
Camera flashlight modification
Simulink simulation of ESP three-phase SVPWM controller
[pyGame practice] playing poker? Win or lose? This card game makes me forget to eat and sleep.
Smart headline: smart clothing forum will be held on August 4, and the whole house smart sales will exceed 10billion in 2022
第三篇 RBAC权限管理 数据库设计详解
BGP basic configuration
STL map操作
Dynamic planning - force buckle
Redis布隆过滤器
JSD-2204-会话管理-过滤器-Day19
Activity的启动流程









