Last active
September 23, 2015 00:18
-
-
Save EduardoMil/dfb91c4bfcb7ef33b661 to your computer and use it in GitHub Desktop.
Comecei a desenvolver um algorítimo que soma dois números (a+b) e guarda o resultado em c; Mas não sei como descobrir se esse número excedeu o tamanho que uma variavel do tipo "int" suporta. (2147483647)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
int tamanhodeinteiro (){ | |
unsigned int i,j; | |
for (i=0; j=pow(2,i); i++){ | |
j=pow(2,i); | |
printf("2 ^ %d = %d \n", i,j); | |
} | |
printf("o ultimo numero eh o tamanho maximo que um numero inteiro pode alcancar \n\n"); | |
return (0); | |
} | |
int main (){ | |
unsigned int a,b,lim=2147483647,c; | |
tamanhodeinteiro(); | |
printf("Digite um numero: "); | |
scanf("%d",&a); | |
printf("Digite um segundo numero: "); | |
scanf("%d",&b); | |
printf ("\n Numero armazenado A:%d, B:%d\n",a,b); | |
if (a>lim || b>lim){ | |
printf("\n Seu numero ja excedeu o primeiro limite\n"); | |
} | |
else { | |
if (a>lim-b && b>lim-a){ | |
printf ("Seu numero estorou\n\n\n\n"); | |
if (a>0 || b>0) | |
printf("Deu certo"); | |
} | |
else{ | |
printf("\n Seu numero nao estorou"); | |
c=a+b; | |
printf(" a soma eh: %d \n",c); | |
} | |
} | |
return (0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment