68 lines
1.1 KiB
C
68 lines
1.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
/* Marche pas la precision pour enlver avec -1*/
|
|
|
|
|
|
|
|
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 = 10;
|
|
int ans = racinecarre(n);
|
|
printf("%d\n", ans);
|
|
|
|
int tab1[] = {9, 25, 4};
|
|
int resultat1[3];
|
|
racineCarreeTab(tab1, 3, resultat1);
|
|
printf("racineCarreeTab([9,25,4]) = %d , %d , %d ", resultat1[0], resultat1[1], resultat1[2]);
|
|
printf("\n");
|
|
|
|
int tab2[] = {10, 36,-1};
|
|
int resultat2[3];
|
|
racineCarreeTab(tab2, 3, resultat2);
|
|
printf("racineCarreeTab([10, 36,-1]) = %d, %d, %d ", resultat2[0], resultat2[1], resultat2[2]);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|