This commit is contained in:
2025-10-15 16:26:07 +02:00
commit 6565163d11
6 changed files with 240 additions and 0 deletions

76
Exo3.c Normal file
View File

@@ -0,0 +1,76 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int TAILLE_TAB = 4;
int racineCarree(int n){
if (n < 0){
return -2;
}
for(int i = 0; i<n/2 ; i++){
if (i*i == n){
return i ;
}
}
return -1;
}
int racineCarreeTab(int tab[]){
for(int i = 0; i < TAILLE_TAB; i++){
tab[i] = racineCarree(tab[i]);
}
}
void TriSpecial(int tab[], int TAILLE_TAB) {
int i, NbNonEntier = 0;
long somme = 0;
long sommeRacines = 0;
int tmp[TAILLE_TAB];
for (i = 0; i < TAILLE_TAB; i++) {
int r = racineCarree(tab[i]);
if (r == -1) NbNonEntier++;
somme += tab[i];
if (r != -2) sommeRacines += (r == -1 ? r : r);
}
if (NbNonEntier % 2 == 0) {
for (i = 0; i < TAILLE_TAB; i++) {
if (i % 2 == 0) tmp[i] = tab[i];
else
tmp[i] = somme * tab[i];
}
} else {
for (i = 0; i < TAILLE_TAB; i++) {
if (i % 2 == 0) tmp[i] = racineCarree(tab[i]);
else
tmp[i] = sommeRacines * tab[i];
}
}
for (i = 0; i < TAILLE_TAB; i++) {
tab[i] = tmp[i];
}
}
int main (void){
int tabtest[TAILLE_TAB];
srand(time(NULL));
for (int i = 0; i < TAILLE_TAB; i++) {
tabtest[i] = 1000000 + rand() % 1000000;
}
int tab[] = {3,5,25,16} ;
TriSpecial(tab, TAILLE_TAB);
for (int i = 0; i<TAILLE_TAB; i++){
printf("%d ", tab[i]);
}
}