Sabtu, Juli 18, 2015

Program C Convert Decimal to Binary

main()
{
 signed int a,b,c,e[100];
 unsigned char d,f;
 printf("input a number! ");
 scanf("%d", &a);
 printf("binary of decimal %d is ",a);

 for(;;)
 {
  d=d+1;
  b=trunc(a/2);
  c=a%2;
  e[d]=c;
  a=b;
  if (b==0) break;
 }

 f=0;

 for (;;)
 {
  printf("%d", e[d-f]);
  f=f+1;
  if (f==d) break;
 }

 getch();
}


If there is something not understand, please asked... : ) Hope it is useful, thank you... :)

0 komentar: