TP18
This commit is contained in:
BIN
DEV1.1/TP18/palindrome
Executable file
BIN
DEV1.1/TP18/palindrome
Executable file
Binary file not shown.
31
DEV1.1/TP18/palindrome.c
Normal file
31
DEV1.1/TP18/palindrome.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char* inverse(const char* s){
|
||||
int ind=0,i;
|
||||
char lettre;
|
||||
char* tab_inv=(char*) malloc((strlen(s)+1)*sizeof(char));
|
||||
for(i=strlen(s)-1; i>=0;i--){
|
||||
tab_inv[ind]=s[i];
|
||||
ind++;
|
||||
}
|
||||
tab_inv[ind]='\0';
|
||||
return tab_inv;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int mot;
|
||||
char* arg=NULL;
|
||||
for (mot=1;mot<argc;mot++){
|
||||
arg=inverse(argv[mot]);
|
||||
if (strcmp(arg,argv[mot])==0)
|
||||
printf("%s est un palindrome",argv[mot]);
|
||||
else
|
||||
printf("%s n'est pas un palindrome",argv[mot]);
|
||||
if (mot<argc-1)
|
||||
printf(",\n");
|
||||
}
|
||||
printf(".\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
BIN
DEV1.1/TP18/precognition
Executable file
BIN
DEV1.1/TP18/precognition
Executable file
Binary file not shown.
35
DEV1.1/TP18/precognition.c
Normal file
35
DEV1.1/TP18/precognition.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
int main(void) {
|
||||
int pris=0,val=1,val1,occ,nbr_val=0;
|
||||
double* tab=NULL;
|
||||
double* tab_val=NULL;
|
||||
tab = (double*) malloc(sizeof(double));
|
||||
printf("Réel à entrer: ");
|
||||
pris=scanf("%lf",tab[nbr_val]);
|
||||
while(pris!=0){
|
||||
tab = (double*) realloc(tab,nbr_val*sizeof(double));
|
||||
printf("Réel à entrer: ");
|
||||
pris=scanf("%lf",tab[nbr_val]);
|
||||
nbr_val++;
|
||||
}
|
||||
tab_val = (double*) malloc(nbr_val*sizeof(double));
|
||||
printf("%3f ",tab[0]);
|
||||
tab_val[0]=tab[0];
|
||||
for(val=1;val<nbr_val;val++){
|
||||
occ=0;
|
||||
for(val1=0;val1<nbr_val;val1++){
|
||||
if (tab[val]==tab_val[val1])
|
||||
occ++;
|
||||
}
|
||||
if (occ==0)
|
||||
printf("%3f ",tab[val]);
|
||||
tab_val[val]=tab[val];
|
||||
}
|
||||
free(tab);
|
||||
free(tab_val);
|
||||
printf("\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user