Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
guia 4 terminada
#include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> #include <math.h> typedef struct { char number[101]; unsigned short x; unsigned short y; }datos; // Prototypes. unsigned short checkTheNumber(char *, unsigned short); //unsigned long long convertToBase10(char *, unsigned short ); void baseConversion(unsigned long long, unsigned short, char *); void *investNumber(char *); // --------------------------------------Main program----------------------------------------- int main(void) { unsigned short i; unsigned short N; unsigned long long numberTo10; char array[101]; char * pEnd; scanf("%hu\n", &N); datos numeros[N]; for (i = 0 ; i < N ; i++) scanf("%100s %hu %hu", numeros[i].number, &numeros[i].x, &numeros[i].y); for (i = 0 ; i < N ; i++) if (checkTheNumber(numeros[i].number, numeros[i].x)) { numberTo10 = strtoull(numeros[i].number, &pEnd,numeros[i].x); //printf("%llu\n", numberTo10); if ( numeros[i].y == 10) printf("El numero %s escrito en base %hu es igual a %llu en base %hu.\n", numeros[i].number, numeros[i].x, numberTo10,numeros[i].y); else { baseConversion(numberTo10, numeros[i].y, array); printf("El numero %s escrito en base %hu es igual a %s en base %hu.\n", numeros[i].number, numeros[i].x, array,numeros[i].y); } } else printf("El numero %s NO se encuentra en base %hu.\n", numeros[i].number, numeros[i].x); return 0; } unsigned short checkTheNumber(char *number, unsigned short base) { unsigned short digit; if (base < 11) { while ( *number != '\0') { if ( isalpha( *number )) return 0; digit = ( (unsigned short) *number ) - 48; if (digit >= base) return 0; number ++; } } else { while ( *number != '\0') { if ( isalpha ( *number ) ) { if ( islower( *number ) ) *number = toupper( *number ); digit = (unsigned short) *number - 55; if ( digit >= base) return 0; } else { digit = ( (unsigned short) *number ) - 48; if (digit >= base) return 0; } number ++; } } return 1; } void baseConversion(unsigned long long number, unsigned short base, char *numero) { short i; char sum[101]; unsigned long long rest; char numbers[17] = "0123456789ABCDEF"; //char *array = sum; i = 0; while ( number > 0) { rest = number % base; sum[i] = numbers[rest]; number /= base; i ++; } sum[i] = '\0'; investNumber(sum); strcpy(numero, sum); } void *investNumber(char *number) { char *digit = number; char num[101]; unsigned short length; short i; length = strlen(number); num[length] = '\0'; for (i = length - 1 ; i >= 0 ; i--) { num[i] = *digit; digit ++; } strcpy(number, num); }
run
|
edit
|
history
|
help
0
PRÁCTICA DE QUICKSORT
-Wconversion double -> int
CO_assign_q1
WrongWay reversible iterator Copyright(C) 2016 Henry Kroll III www.thenerdshow.com
B_141128_MatrizProducto
C)_Assign_q4
Michael Bean's Spring 2017 Lab 3 v1.1
Atomic Openmp
Atoi without minus
18BCE2182 MIDTERM QUES-2