Difference between revisions of "Solução: Problema do quadrado perfeito (Rafael Dourado)"

From AdonaiMedrado.Pro.Br
Jump to: navigation, search
(New page: #include <stdio.h> #include <math.h> int main (void) { int entrada,i,k; int contador=0,resposta=0; int * numero = NULL; do { for (i=0;i<10;i++) { ...)
 
Line 1: Line 1:
 +
<code lang="c">
 
#include <stdio.h>  
 
#include <stdio.h>  
 
#include <math.h>
 
#include <math.h>
Line 29: Line 30:
 
     system ("pause");
 
     system ("pause");
 
}
 
}
 +
</code>

Revision as of 16:38, 5 June 2009

#include <stdio.h> 
#include <math.h>
 
int main (void)
{
    int entrada,i,k;
    int contador=0,resposta=0;
    int * numero = NULL;
 
    do {
        for (i=0;i<10;i++)
        {
            scanf ("%d", &entrada);
            if (entrada==0)
               break;
            contador++;
            numero = (int*) realloc (numero, contador * sizeof(int));
            k = sqrt(entrada);
            if (k*k == entrada)
               resposta++;
        }
        if (entrada==0)
           break;
 
    } while (entrada!=0);
 
    printf ("%d\n", resposta);
    free (numero);
    system ("pause");
}