当前位置:网站首页>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;
}
边栏推荐
- Unreal中通过FMonitoredProcess启动其他独立程序
- Uniapp realizes horizontal click and slide menu
- Blazor quickly realizes Minesweeper
- 基于matlab的CBOC信号调制解调仿真,输出其相关性,功率谱以及频偏跟踪
- 【Pygame实战】飞机射击大作:宇宙激战一触即发...这款超经典的射击游戏也该拿出来重启了~
- [hiflow] regularly send Tencent cloud SMS sending group
- JSD-2204-会话管理-过滤器-Day19
- Vision and intelligent learning recent journal reading and related knowledge learning
- 颜值爆表 Redis官方可视化工具来啦,针不戳
- 修改ssh命令行[[email protected]]#颜色
猜你喜欢

What is the difference between server hosting and virtual host

智头条:智装论坛将于8月4日举行,2022全屋智能销售将破100亿

报错 | cannot read property ‘_normalized‘ of undefined

百度工程师眼中的云原生可观测性追踪技术

Exploration and practice of Ali multimodal knowledge atlas

494. Objectives and

Xlswriter - Excel export

基于matlab的CBOC信号调制解调仿真,输出其相关性,功率谱以及频偏跟踪

基于simulink的双闭环矢量控制的电压型PWM整流器仿真

Part II how to design an RBAC authority system
随机推荐
Time series data in industrial Internet of things
STL deque
Modify SSH command line[ [email protected] ]Color
修改ssh命令行[[email protected]]#颜色
解决kotlin写Android项目编译报Execution failed for task ‘:app:kaptDebugKotlin‘.异常
【Pygame实战】飞机射击大作:宇宙激战一触即发...这款超经典的射击游戏也该拿出来重启了~
RTA is a new way to accurately launch advertisements?
Matlab simulation of depth information extraction and target ranging based on binocular camera images
7.13web safety operation
xlswriter - excel导出
VMware virtual machine download, installation and use tutorial
After vscode is updated, the shortcut keys related to tab cannot be used
Simulation of synchronization performance of BOC modulation and demodulation based on MATLAB, output tracking curve and identification curve under different lead lag code distance
Matlab simulation of Turbo code error rate performance
【OpenCV 例程200篇】225. 特征提取之傅里叶描述子
[hiflow] regularly send Tencent cloud SMS sending group
The best time to buy and sell stocks
Skills to learn before going to primary school
The exclamation point of vscode +tab shortcut key cannot be used, and the solution to the problem of a-soul-live2d plug-in
深入理解CAS (自旋锁)