So im answering an assignment question in c and for some reason when I run it in codeblocks or even C lion I get a different and wrong answer than when I run it on Repl.it online. I copied and pasted the code so there are no errors or differences. The question itself requires u to enter a 12 digit ISBN number then calculate the product by takin (1st number) X 1 + (second number) X 3 and so on then taking the mod of the sum and subtracting from 10 and calculate the last digit.
Ex the number 978030640615 should give the product as 93 and last digit as 7
Below is my code for code blocks:
#include <stdio.h>
int main(void) {
long num1 = 0;
int num2 =0;
int sum =0;
int n = 0;
printf("Enter number :\n");
scanf("%ld",&num1);
for (int i= 0 ; i<12 ; i++){
num2 = 0;
num2 = num1%10;
num1 = num1/10;
n +=1;
if (n%2 == 0){
num2 = num2*1;
//printf("%d" , num3);
}
else {
num2 = num2*3;
//printf("%d", num2);
}
sum = num2+sum;
}
printf("\n" "%d", sum);
num2 = sum%10;
num2= 10 - num2;
printf("\n" "%d", num2);
}
and the output is -63 and 13
My code for Repl.it is the same as the one from codeblocks I copied and pasted it but i get 93 and 7 as the answer