ajout controle
This commit is contained in:
56
Exercice1.c
Normal file
56
Exercice1.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#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");
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user