hw6p2.c - #define_CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <math.h>#include <time.h>#include <stdlib.h>*Author Ruben Valle Ramirez date inputs

# hw6p2.c - #define_CRT_SECURE_NO_WARNINGS#include...

This preview shows page 1 - 2 out of 2 pages.

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> #include <time.h> #include <stdlib.h> /*Author: Ruben Valle Ramirez date: 3/23/20 inputs: 12 digits outputs: returns the sum of odd indexes of the array, sum of the even indexes, the sum of the odds and evens, and returns whether the barcode is valid or not */ void check(int code[], int result, int odd, int even) { //i had these before the final edits of the code, just ignore them int i = 1; even = 0; odd = 0; result = 0; //initialization of the integers while (i < 11) { //this loop gets the odd indices by using i = 1 to i = 9 odd += code[i]; //this gets the sum of the odd indices i += 2; //this makes sure that only the odds get added by increasing i by 2 } i = 0; //i gets set to 0 to begin the evens while (i < 12) { //this loop gets the even indices by using i = 0 to i = 10 even += code[i]; //this gets the sum of the evens i += 2; //this makes sure that only the events are added by increasing i by 2 } if ((3 * odd + even) % 10 != 0) { //if the sum of the odd and even numbers does not end with 0 result = 10 - ((3 * odd + even) % 10); //the result = 10 minus the

#### You've reached the end of your free preview.

Want to read both pages?

• Spring '08
• Grubbs
• Numerical digit, Decimal, Parity, int CODE, sum of odd indexes of the array
Stuck? We have tutors online 24/7 who can help you get unstuck.
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes