c - How to use arithmatic operations on uint64_t? -
i trying make program divides number given number , prints out remainder , solution of given number divided 10. code isnt printing out correct values. here following code:
#include <stdio.h> #include <string.h> #include <stdint.h> #include <stdlib.h> uint64_t divide(uint64_t,uint64_t); int main(int argc, char *argv[]) { uint64_t num1 = 224262; uint64_t num2 = 244212; divide(num1,num2); } uint64_t divide( uint64_t set1, uint64_t set2 ) { printf("%lx\n",set1); uint64_t remainder = set1%10; printf("%lx\n",remainder); set1= set1/10; printf("%lx\n",set1); }
currently output of gives me following
36c06 2 579a
how have correctly outputs divided value , remainder?
assuming platform has long
size 64 bits
, correct format printf
s %lu
uint64_t divide( uint64_t set1, uint64_t set2 ) { printf("%lu\n",set1); uint64_t remainder = set1%10; printf("%lu\n",remainder); set1= set1/10; printf("%lu\n",set1); return set1; }
using predefined format specifier of inttypes.h
can write
#include <stdio.h> #include <string.h> #include <stdint.h> #include <stdlib.h> #include <inttypes.h> uint64_t divide(uint64_t,uint64_t); int main(int argc, char *argv[]) { uint64_t num1 = 224262; uint64_t num2 = 244212; divide(num1,num2); } uint64_t divide( uint64_t set1, uint64_t set2 ) { printf("%"priu64"\n",set1); uint64_t remainder = set1%10; printf("reminder = %"priu64"\n",remainder); set1= set1/10; printf("division = %"priu64"\n",set1); return set1; }
Comments
Post a Comment