Files
CONTROLE_DEV51_aissi/Exercice1/racinecarree.c
Aissi Jude Christ 1eab17d713 Rendu
2025-10-15 16:49:17 +02:00

117 lines
6.0 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
#include <stdlib.h>
int racineCarree(int nombre){
if (nombre < 0) {
return -1;
}
if ( nombre == 0) {
return 0;
}
int i;
for (i = 0; i <= nombre; i++) {
if( i * i == nombre){
return i;
}
if ( i * i > nombre ) {
return -1;
}
}
return -1;
}
void racineCarreeTab(int *tab, int *resultat, int taille) {
int i;
for (i = 0; i < taille; i++){
resultat[i] = racineCarree(tab[i]);
}
}
void afficherTableau(int *tab, int taille) {
printf("[");
int i;
for (i = 0; i < taille; i++) {
printf("%d", tab[i]);
if (i < taille - 1) {
printf(", ");
}
}
printf("]\n");
}
int main() {
/* Pour la racine carrée pour un nombre*/
/*
printf("racineCarree(9) = %d\n", racineCarree(9));
printf("racineCarree(10) = %d\n", racineCarree(10));
*/
/* Pour la racine carrée d'un ensemble de nombres positifs*/
/*
int tab1[] = {9, 25, 4};
int taille1 = 3;
int resultat1[3];
/* Racine carrée dun ensemble de nombre entier positif
printf("Entrée: ");
afficherTableau(tab1, taille1);
racineCarreeTab(tab1, resultat1, taille1);
printf("Résultat : ");
afficherTableau(resultat1, taille1);
*/
/*
int tab2[] = {10,36,2};
int taille2 = 3;
int resultat2[3];
printf("Entrée: ");
afficherTableau(tab2, taille2);
racineCarreeTab(tab2, resultat2, taille2);
printf("Résultat : ");
afficherTableau(resultat2, taille2);
return 0;
*/
int tab2[] = {10000000000000000000000000000000000000000000,360000000000000000000000000000000000000,200000000000000000000000000000000,82370386, 29610, -1069985664, 32767, 785898610, 29610, 1818272, 0, 1818272, 0, 782370386, 29610, 0, 0, -1069985584, 32767, 785901680, 29610, 1685382484, 4, 0, 0, 1979960, 0, -1069984976, 32767, 784369984, 29610, 785645568, 29610, 0, 0, 0, 0, -1069985552, 32767, 785872957, 29610, 0, 0, 782370386, 29610, -1069985248, 32767, 785867862, 29610, 0, 0, -1069984976, 32767, 785872896, 29610, -1069985008, 32767, 0, 0, -1069984976, 32767, -1069985280, 32767, 785935300, 29610, 786105072, 29610, 785645568, 29610, 786103712, 29610, 785645568, 29610, 0, 0, 0, 0, -1577058304, -32654, -931921920, -413901394, 0, 0, 0, 0, -1572864000, -32654, -1069985344, 32767, -1069985440, 32767, 1, 3, 0, 0, 0, 0, -1069985472, 32767, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 0, 785646912, 29610, -1069983840, 32767, 785875941, 29610, 1, 29610, 786103712, 29610, 0, 0, 785874083, 29610, 1, 22574, 785645568, 29610, -1069985264, 32767, 785874083, 29610, 1, 0, 786105072, 29610, -1069985232, 32767, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1069985200, 32767, -1069985232, 32767, -1069984912, 32767, -1069985232, 32767, 2, 0, 786105072, 29610, 0, 0, 3, 0, -1069985264, 32767, 0, 0, 0, 0, 0, 32767, 786105072, 29610, 0, 0, 0, 29610, 0, 0, 0, 0, 0, 0, 0, 0, 785645568, 29610, 0, 0, 782335800, 29610, 782370386, 29610, 786103712, 29610, 0, 0, -1069984912, 32767, 1024, 0, 786103712, 29610, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 785902445, 29610, 0, 2, 785647232, 29610, 0, 0, 1842243024, 0, 782259552, 29610, 785645568, 29610, -1069984448, 32767, 785903545, 29610, 2328, 0, 782335800, 29610, 785645568, 29610, -1069984504, 32767, -1069984508, 32767, 0, 0, 0, 0, 0, 0, 0, 0, 785902445, 29610, 3, 2, 785647232, 29610, 782246840, 29610, 1038094022, 0, 782259552, 29610, 785645568, 29610, -1069984304, 32767, 785903545, 29610, 1615, 0, 782335800, 29610, 785645568, 29610, -1069984360, 32767, -1069984364, 32767, 785647024, 29610, -431209048, 22574, 785902343, 29610, -1069983992, 32767, 1842243024, 0, 3, 0, 1416958013, 0, 785859888, 29610, 786103712, 29610, -1069984176, 32767, 785903545, 29610, 3, 0, 785860824, 29610, 786103712, 29610, -1069984232, 32767, -1069984236, 32767, 0, 0, 786106576, 29610, -1069983920, 32767, 786045000, 29610, 786106000, 29610, 3, 0, 785646944, 29610, 785859728, 29610, -1069984236, 32767, -1069984008, 32767, -1069984000, 32767, 0, 0, 0, 0, 786041589, 29610, 785860824, 29610, 0, 0, 0, 0, 786046323, 29610, 0, 0, 786041589, 29610, 786106000, 29610, -1069983848, 32767, 1416958012, 0, -1069983888, 32767, 785905858, 29610, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 786105072, 29610, -1069983984, 32767, 785924214, 29610, 0, 29610, 0, 0, -1069983952, 32767, -1069983968, 32767, 0, 0, 786106000, 29610, 0, 0, -74416640, 85883941, 786105072, 29610, 1, 0, 786105072, 29610, 0, 0, -1069983904, 32767, 782508275, 29610, 144, 3, 40, 0, 0, 0, 0, 0, 0, 0, 782841048, 29610, 0, 3, -74416640, 85883941, 786105072, 29610, 1, 0, -1069983840, 32767, 782924028, 29610, 0, 0, -1, -1, 0, 0, -74416640, 85883941, 1437325202, 18317, 785949280, 29610, -1069983152, 32767, 785997433, 29610, 0, 0, 0, 0, 0, 0, 0, 0, 785635136, 29610, 786103128, 29610, 786103712, 29610, 1437311183, 18317, 786105072, 29610, 786046464, 29610, 0, 0, 0, 0, 0, 0, 0, 0, 785851032, 29610, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 783406880, 29610, 335544324, 0, 782492992, 29610, -1, -1, 0, 0, 784374464, 29610, 8904, 0, 784374560, 29610, 0, 0, -431205327, 22574, -1069983136, 32767, 782921024, 29610, -1069982960, 32767, 0, 0, 3720, 0, 2592, 0, 1, 0, -431210496, 22574, -1069983056, 32767, 0, 12779520, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 486449152, 22575, -1069983424, 32767, 782911174, 29610, -1069983296, 32767, 782914766, 29610, 2, 9175849, 4, 0, 143360, 0, 486449152, 22575, 8944, 0, 0, 0, 143360, 0, -74416640, 85883941, 8, 0, -74416640, 85883941, -1069983072, 32767, 783407269, 29610, 0, 0, 555, 0, 0, 0, 10000, 0, 0, 0, 10000, 0, 783406880, 29610, -1, -1, 0, 0, 784374464, 29610, 8904, 0, 784374560, 29610, 0};
int taille2 = 10000;
int resultat2[10000];
printf("Entrée: ");
afficherTableau(tab2, taille2);
racineCarreeTab(tab2, resultat2, taille2);
printf("Résultat : ");
afficherTableau(resultat2, taille2);
return 0;
}