Decimal to Binary Conversion Algorithm

Program Program Source #include <stdio.h> int main() { int array[20]; int dvalue,b=1,c=0,t=0; printf(“Enter an decimal\n”); scanf(“%d”,&dvalue); while(b!=0) { array[t]=c=dvalue%2; b=dvalue=dvalue/2; t++; } printf(“Binary representation of your entered value\n”); int i; for(i=–t;i>=0;i–) { printf(“%d”,array[i]); } return 0; }

Decimal to Binary Conversion Algorithm(another method)

Program Program Source #include <stdio.h> int main() { int decimal,remainder=0,binary=0,tenbase=1; printf(“Enter an decimal\n”); scanf(“%d”,&decimal); while(decimal>0) { remainder=decimal%2; binary=binary+remainder*tenbase; tenbase=tenbase*10; decimal=decimal/2; } printf(“Binary representation of your entered value\n”); printf(“%d”,binary); return 0; }