skcratch Posted November 28, 2007 at 12:41 AM Report Share #150829 Posted November 28, 2007 at 12:41 AM Viva! Será que alguém me podia dizer se existe alguma representação tipo constante (ou algo desse género), para o maior número inteiro que se pode representar em C? Grato desde já pela ajuda! Cumps! 🙂 Link to comment Share on other sites More sharing options...
skcratch Posted November 28, 2007 at 12:55 AM Author Report Share #150834 Posted November 28, 2007 at 12:55 AM Viva! Julgo que seja a constante INT_MAX. Cumps! 🙂 Link to comment Share on other sites More sharing options...
Triton Posted November 28, 2007 at 09:48 AM Report Share #150853 Posted November 28, 2007 at 09:48 AM Sim, essas informações estão no ficheiro limits.h. Aqui fica um exemplo: int main(int argc, char *argv[]) { printf("TYPE \t\t BYTES \t SMALLEST \t\t LARGEST\n\n"); printf("signed char \t %zd \t %hhd \t\t\t %hhd\n", sizeof(signed char), CHAR_MIN, CHAR_MAX); printf("unsigned char \t %zd \t 0 \t\t\t %hhu\n\n", sizeof(unsigned char), UCHAR_MAX); printf("signed int \t %zd \t %d \t\t %d\n", sizeof(signed int), INT_MIN, INT_MAX); printf("unsigned int \t %zd \t 0 \t\t\t %u\n\n", sizeof(unsigned int), UINT_MAX); printf("signed short \t %zd \t %hd \t\t %hd\n", sizeof(signed short), SHRT_MIN, SHRT_MAX); printf("unsigned short \t %zd \t 0 \t\t\t %hu\n\n", sizeof(unsigned short), USHRT_MAX); printf("signed long \t %zd \t %ld \t %ld\n", sizeof(signed long), LONG_MIN, LONG_MAX); printf("unsigned long \t %zd \t 0 \t\t\t %lu\n\n", sizeof(unsigned long), ULONG_MAX); printf("float \t\t %zd \t %E \t\t %E\n", sizeof(float), FLT_MIN, FLT_MAX); printf("double \t\t %zd \t %E \t\t %E\n", sizeof(double), DBL_MIN, DBL_MAX); return 0; } <3 life Link to comment Share on other sites More sharing options...
nDray Posted December 3, 2007 at 12:35 AM Report Share #151884 Posted December 3, 2007 at 12:35 AM podes sempre calcular 2 ^ (4 * sizeof(tipo)) - 1. até porque int é uma word, e varia consoante a largura do bus da máquina em que se encontra. Link to comment Share on other sites More sharing options...
jonsmau Posted December 3, 2007 at 08:01 PM Report Share #152063 Posted December 3, 2007 at 08:01 PM O máximo q usei foi um numero com 19 digitos, e foi assim: long long int numero=1234567890123456789LL; printf("Numero: %lld", numero); Link to comment Share on other sites More sharing options...
Rui Carlos Posted December 3, 2007 at 08:18 PM Report Share #152070 Posted December 3, 2007 at 08:18 PM podes sempre calcular 2 ^ (4 * sizeof(tipo)) - 1. até porque int é uma word, e varia consoante a largura do bus da máquina em que se encontra. Assim à primeira vista essa fórmula está errada. Para números com sinal deve ficar 2 ^ (8 * sizeof(tipo) - 1) - 1 e sem sinal 2 ^ (8 * sizeof(tipo)) - 1. De qualquer forma é muito mais simples, seguro e eficiente usar as constantes do sistema. Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
souto Posted December 7, 2007 at 09:57 AM Report Share #152830 Posted December 7, 2007 at 09:57 AM O máximo q usei foi um numero com 19 digitos, e foi assim: long long int numero=1234567890123456789LL; printf("Numero: %lld", numero); maior ainda seria unsigned long long int numero; E este sim, o maior de todos 🙂 Link to comment Share on other sites More sharing options...
falk0n Posted December 7, 2007 at 10:11 AM Report Share #152834 Posted December 7, 2007 at 10:11 AM e possivel que seja o maior numero em inteiro , mas penso que o long long seja uma extensao do compilador da gnu, pode nao existir em todos os compiladores de C. boas programacoes Link to comment Share on other sites More sharing options...
Triton Posted December 7, 2007 at 10:15 AM Report Share #152837 Posted December 7, 2007 at 10:15 AM e possivel que seja o maior numero em inteiro , mas penso que o long long seja uma extensao do compilador da gnu, pode nao existir em todos os compiladores de C. boas programacoes Existe em todos os compiladores que suportem a norma C99. <3 life Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now