How do i break a 5 Digit Zipcode so i can later add each digit together and get the check sum digit. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do i break a 5 Digit Zipcode so i can later add each digit together and get the check sum digit.

28th Feb 2018, 3:10 AM
Timew2
Timew2 - avatar
3 Answers
+ 2
Assuming you read the zipcode as an integer: int CheckSum(int zip) { int sum=0; while(zip!=0) { sum+=zip%10; zip/=10; } // To save the digits for later, assign // zip%10 inside array elements. return sum; }
28th Feb 2018, 3:29 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 1
Thank You. but I figured it . I'll post my code shortly
28th Feb 2018, 3:35 AM
Timew2
Timew2 - avatar