当前位置:网站首页>Classic example of C language - commodity inspection code
Classic example of C language - commodity inspection code
2022-07-24 00:26:00 【Blue_ lan18】

Numbers 013800 15173 5 Appears below the barcode . The first 1 A number indicates the type of goods ( Most goods use o perhaps 7 Express ,2 Indicates the goods to be weighed ,3 It means drugs or health-related goods , and 5 Indicates a gift ). The first group 5 Bits are used to identify the manufacturer (13800 It is the code of Nestle frozen food company in the United States ). The second group 5 Digit numbers are used to identify the product ( Including package size ). The last digit is “ Check bit ”, Its only purpose is to help identify errors in the preceding numbers . If there is an error in barcode scanning , So before 11 Digit numbers may not match the last digit , Supermarket scanners will reject the entire barcode .
Here's a way to calculate check bits : First of all 1 position 、 The first 3 position 、 The first 5 position 、 The first 7 position 、 The first 9 Position and number 11 Digit number
Add up ; And then put the 2 position 、 The first 4 position 、 The first 6 position 、 The first 8 Position and number 10 Add the digits ; Take a look at my brother's one-time addition of Luo song to , Then add it to the result of the second addition ; Then subtract from the above result 1; The result of subtraction is divided by 10 Take the remainder ; Last use 9
Subtract the remainder from the previous step .
# 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 It is the inspection code
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;
}
边栏推荐
- AWS Article 3 how to publish message to IOT mqtt in go language
- Gbase 8C system table information function (II)
- Redis 主从、哨兵、集群架构有缺点比较
- Redis分布式锁待续
- July 23, 2022 - mapper file description
- English语法_指示代词 - So
- Try new methods
- Gbase 8C session information function (4)
- paypal订阅流程及api请求
- Gbase 8C access authority query function (II)
猜你喜欢

Understanding polymorphism and letting different "people" do the same thing will produce different results

A good habit to develop when writing SQL

Flutter | specifies the type of page return value

Mobile terminal H5 - a lifeline timeline
CA digital certificate

Redis 集群hash分片算法(槽位定位算法)

Flutter | the easiest way to add header and footer to listview
![[translation] Introduction to go RPC: Hello World](/img/dd/7887f056bc031fe50253078dd355d0.png)
[translation] Introduction to go RPC: Hello World

php实现 Stripe订阅

English grammar_ Demonstrative pronoun -such / the same
随机推荐
Ansible command auto completion
ES6 combines multiple class methods
ansible命令自动补全
Gbase 8C system table information function (I)
mongodb的多数据源配置
Sed in-depth understanding and use
Beifeng communication appeared in China (Xiamen) emergency exhibition | intelligent communication means are strong and eye-catching!
Summary of pit websocket
EFCore高级Saas系统下单DbContext如何支持不同数据库的迁移
Material return on investment
[speech synthesis] tensorflowtts Chinese text to speech
GBase 8c 会话信息函数(三)
Table custom table encapsulation
Application of SCA on devsecops platform
inode、软链接、硬链接
AWS Part 4 one machine and one secret
English语法_指示代词 -such / the same
数据模型设计方法概述
GBase 8c 模式可见性查询函数(一)
Gbase 8C access authority query function (I)