Files
Borland-C/CPP/PROG10.CPP

101 lines
2.1 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Prog10
//
// Programadores:
//
// Juan L¢pez Fern ndez
// Moiss Virumbrales Cuenca
// DAI 1§A
//
// Program que introducido un n£mero decimal, lo cambia a la base
// introducida.
#include<stdio.h>
#include<conio.h>
int numero,base,cociente,j_resto,numeroaux,resto,baseini;
int tabla[15];
char aux;
// Inicializaci¢n de funciones.
void imprimir_num(int j_resto);
//int comprobar_base(baseini);
void main () {
clrscr();
gotoxy (20,11);
printf ("Introduce la base del n£mero: ");
fflush(stdin);
scanf ("%d",&baseini);
gotoxy (20,12);
printf ("Introduce n£mero: ");
for (j_resto=0;j_resto<15;j_resto++) {
fflush(stdin);
cscanf ("%1c",&aux);
if (aux=='t')
j_resto=15;
tabla[j_resto]=aux;
// else
// if (tabla[j_resto]==97)
}
gotoxy (20,13);
printf ("Introduce base: ");
fflush(stdin);
scanf ("%d",&base);
numeroaux=numero;
j_resto=0;
do {
cociente=numeroaux/base;
resto=numeroaux%base;
tabla[j_resto]=resto;
j_resto++;
numeroaux=cociente;
}
while (base<=cociente);
tabla[j_resto]=cociente;
imprimir_num(j_resto);
fflush(stdin);
getch();
}
// Funci¢n imprimir n£mero resultante.
void imprimir_num(int j_resto) {
clrscr();
gotoxy(10,12);
printf ("El n£mero %d en base %d es: ",numero,base);
for (;j_resto>=0;j_resto--) {
if (tabla[j_resto]<=9)
printf ("%d",tabla[j_resto]);
else
if (tabla[j_resto]==10)
printf ("A");
else
if (tabla[j_resto]==11)
printf ("B");
else
if (tabla[j_resto]==12)
printf ("C");
else
if (tabla[j_resto]==13)
printf ("D");
else
if (tabla[j_resto]==14)
printf ("E");
else
if (tabla[j_resto]==15)
printf ("F");
}
}
// Funci¢n comprobar base.
//int comprobar_base(int baseini) {
// if (baseini<=9)
// if (tabla[j_resto]>=baseini)
// error=1;
// else
// if (tabla[j_resto]!=065 || tabla[j_resto]!=097 || tabla[j_resto]!=066
//|| tabla[j_resto]!= 067 || tabla[j_resto]!=068 || tabla[j_resto]!=069)
//}