//Program bases #include #include #include #define base 2 int i, n; int array[100]; char c; double d; void decimal(void); void binario(void); main () { textcolor (9); textbackground (1); do { clrscr (); puts ("Escoje una opci¢n: "); puts (""); puts (" a) Base a decimal."); puts (" b) Decimal a base."); gotoxy (20,1); textcolor (15); clreol (); c = getche (); } while (c != 'a' && c!= 'b'); textcolor (9); clrscr (); printf ("Teclea el n£mero: "); textcolor (15); clreol (); if (c == 'a') decimal(); else binario(); getch (); return 0; } void decimal(void){ for (i=1; array[i-1]!= -35 ; i++) { array[i] = getche() -48; if ((array[i] == -40) && (i != 1)) { gotoxy (wherex(), wherey()) ; clreol(); i-= 2; } if ((array[i] == -40) && (i == 1)) i --; if (array [i] == -3 && i == 1 && array[0] != 1) { array [0]= 1; i--; } if ((((array[i] < 0) || (array[i] >= base)) && array[i] != -35 && array[i] != -40) || (array[i] == -3 && i != 1)) { gotoxy (wherex()- 1, wherey()); clreol (); i--; sound (500); delay (30); nosound (); printf ("\a"); } } puts (""); i-= 2; n= i; for (; i>0; i--) d += pow(base,n-i)*array[i]; if (array [0] == 1) d *= -1; printf ("\n%1.0f", d); } void binario(void) { scanf ("%d", &n); for (i=0; n>0; i++) { array[i] = n % base; n /= base; } for (; i>0; i--) printf ("%d", array[i-1]); }