58 lines
913 B
C
58 lines
913 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
|
||
|
|
||
|
int racinecarre(int n){
|
||
|
/* int x = n/4; /* Precision pour essayer de se rapprocher*/
|
||
|
|
||
|
if (n < 0){
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
for(int i = 0; i <= n; i++ ){
|
||
|
if (i * i == n) { /* 2 * 2 = 4 */
|
||
|
return i;
|
||
|
}
|
||
|
if (i * i > n) {
|
||
|
break;
|
||
|
}
|
||
|
/*x = (x + ( n / x)) /2;*/
|
||
|
}
|
||
|
return -1;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
int racineCarreeTab(int tableau[], int taille, int resultat[]) {
|
||
|
for (int i = 0; i < taille; i++) {
|
||
|
resultat[i] = racinecarre(tableau[i]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
int main(void)
|
||
|
{
|
||
|
/*
|
||
|
int n = 4;
|
||
|
int ans = racinecarre(n);
|
||
|
printf("%d\n", ans);
|
||
|
*/
|
||
|
|
||
|
int tab1[] = {1100000, 1100000, 110000};
|
||
|
int resultat1[3];
|
||
|
racineCarreeTab(tab1, 3, resultat1);
|
||
|
printf("racineCarreeTab([9,25,4]) = %ld/n, %ld/n , %ld/n", resultat1[0], resultat1[1], resultat1[2]);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
|