0 7 9 4 0 0 8 0 4 5 0 1 0 2 4 0 0 0 1 6 2 8 6 0 0 1 1 1 1 0 8 5 6 8 0 7 0 5 1 0

# 0 7 9 4 0 0 8 0 4 5 0 1 0 2 4 0 0 0 1 6 2 8 6 0 0 1 1

This preview shows page 1 - 4 out of 8 pages.

0 7 9 4 0 0 8 0 4 5 0 1 0 2 4 0 0 0 1 6 2 8 6 0 0 1 1 1 1 0 8 5 6 8 0 7 0 5 1 0 0 0 1 3 8 1 0 1
Answer : Implementation: â€¢ Take a 12 digit code from user. Use integer array to store this 12 digit code. â€¢ The array index start from 0 and goes to 11. â€¢ Use a for() loop to take input from user. /*for() loop to initilize value from 0-11*/ for(i=0;i<12;i++) { scanf("%d",&arr[i]); /*read input*/ } â€¢ Use another for() loop to calculate the sum of digits in the odd- numbered positions and even-numbered positions. â€¢ Inside the for() a j variable is initialized with a value of 1. This variable is incremented by a unit value for each iteration performed by the loop. â€¢ This j variable is used to find out the even and odd positions. This is done by using an if() statement. If j is divisible by 2 then it calculates the sum of even number else the same operation is done for odd numbers. for(i=0;i<11;i++) { j = j+1; /* *check the value of 'j' is divisible by 2 or not *if() statement will executes if it is not divisible by 2, *else else() part will execute
*/ if(j%2!=0) { /*sum of digits in the odd-numbered positions*/ odd_sum = odd_sum + arr[i]; } else { /*sum of digits in the even-numbered positions*/ even_sum = even_sum + arr[i]; } } â€¢ Multiply the sum of odd-numbered position by 3. odd_sum = (odd_sum*3);/*multiply by 3 to odd_sum*/ â€¢ Calculate the sum of even-numbered and odd-numbered positions. sum = odd_sum + even_sum; â€¢ Find the last digit of sum, by using modulus operator(%). last_digit = sum%10; /*to find the last digit*/ â€¢ If the last digit of sum is equals to 0 then print â€œvalidatedâ€ ± , else subtract the last digit from 10 and compare with the final digit of the 12 digit. If both are equal then print â€œvalidateâ€ ± else print â€œerror in bar codeâ€ ± .

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

Want to read all 8 pages?

• Summer '16
• boer
• Elementary arithmetic, Even and odd functions, Parity, Evenness of zero, sum of the digits