exo1 fini

This commit is contained in:
vaisse
2025-10-15 14:47:54 +02:00
commit 597c05be6e
2 changed files with 57 additions and 0 deletions

BIN
exo1/a.out Executable file

Binary file not shown.

57
exo1/racine.c Normal file
View File

@@ -0,0 +1,57 @@
#include <stdlib.h>
#include <stdio.h>
#define LIMIT 256
long racineCarree(long n){
for(long i=0; i<(n/2); i++){
if((i*i)==n){
return i;
}
}
return -1;
}
long* racineCarreeTab(long* tab, int count){
long* rst = (long*) malloc(LIMIT*sizeof(long));
for(long i=0; i<count; i++){
rst[i] = racineCarree(tab[i]);
}
return rst;
}
int main(int argc, char** argv){
/*variables*/
long* tab = (long*) malloc(LIMIT*sizeof(long));
long* rst = (long*) malloc(LIMIT*sizeof(long));
int count = 0;
/*tests*/
if(argc < 2){
printf("USAGE:./a.out <entier(s) strictement(s) positif(s)>\n");
return EXIT_FAILURE;
}
for(int i=1; i<argc; i++){
if((strtol(argv[i], NULL, 10)<0)||(strtol(argv[i], NULL, 10)==0L)){
printf("FORMAT:entier strictement positif\n");
return EXIT_FAILURE;
}
tab[i-1] = strtol(argv[i], NULL, 10);
count++;
}
/*prog*/
if(argc == 2){
printf("racineCarree de %ld = %ld\n", strtol(argv[1], NULL, 10), racineCarree(strtol(argv[1], NULL, 10)));
} else {
rst = racineCarreeTab(tab, count);
printf("racineCarreeTab : \n");
for(int i=0; i<count; i++){
printf(" . racine de %ld = %ld\n", tab[i], rst[i]);
}
}
return EXIT_SUCCESS;
}