c - Doesn't work if the number of digits bigger than 10 -
i want make program input number , print 2 numbers, 1 odd digits , second digits.
it works fine if number of input's digits less 10 when gets number 10 , more digits wrong. know why?
unsigned long int n; unsigned long int even=0,odd=0; int countodd=1,counteven=1; printf("enter every number: \n"); scanf("%lu",&n); while(n!=0){ if(n%2==0){ even+=10*counteven*(n%10); counteven*=10; } else { odd+=10*countodd*(n%10); countodd*=10; } n=n/10; } printf("the odd number %d \n",odd/10); printf("the number %d \n\n\n",even/10);
unsigned long
32-bit on machine, biggest value can hold 232 - 1 (4294967295
), inputting number bigger.
try unsigned long long
instead, @ least 64-bit.
Comments
Post a Comment