Files
CONTROLE_DEV51_DUBREUIL/Exercice1.c

56 lines
1007 B
C
Raw Permalink Normal View History

2025-10-15 16:42:13 +02:00
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int racineCarree(int n){
if(n < 0){
return -1;
}
for(int i = 0; i <= n; i++){
if((i*i) == n){
return i;
}
}
return -1;
}
void racineCarreeTab(int tab[], int taille){
for(int i = 0; i < taille; i++){
tab[i] = racineCarree(tab[i]);
}
}
int main(void) {
int Ex1T1[] = {9, 25, 4};
int Ex1T2[] = {10, 36, 2};
int Ex1Taille = 3;
srand(time(NULL));
int Ex2Taille = 500;
int Ex2Tableau[Ex2Taille];
for (int i = 0; i < Ex2Taille; i++) {
Ex2Tableau[i] = 1000 + rand();
}
printf("Exercice 1a : %d \n", racineCarree(9));
printf("Exercice 1b : ");
racineCarreeTab(Ex1T2, Ex1Taille);
racineCarreeTab(Ex1T1, Ex1Taille);
for(int i = 0; i < Ex1Taille; i++){
printf("%d ", Ex1T1[i]);
}
printf("\n");
for(int i = 0; i < Ex1Taille; i++){
printf("%d ", Ex1T2[i]);
}
printf("\n");
}