Backup proyecto Joyfe - Borland
This commit is contained in:
101
CPP/PROG10.CPP
Normal file
101
CPP/PROG10.CPP
Normal file
@ -0,0 +1,101 @@
|
||||
// Prog10
|
||||
//
|
||||
// Programadores:
|
||||
//
|
||||
// Juan L<>pez Fern<72>ndez
|
||||
// Mois<69>s 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<63>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<63>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<63>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)
|
||||
|
||||
|
||||
//}
|
||||
Reference in New Issue
Block a user