c - Different answer in CodeBlocks in windows and Gedit on Linux Decimal to Binary Conversion -
this code of converting decimal binary. when test on cb number 5 , 20 gave me weird answers ( 100, 10098) when tested on gedit on linux, fine ( 101, 10100).
#include <stdio.h> #include<math.h> int main() { int n; printf("enter int:"); scanf("%d",&n); int result=0, c=0; while(n>0) { if(n%2==1){ result += pow(10,c); } c++; n=n/2; } printf("%d\n",result); }
Comments
Post a Comment