27 Avril
This commit is contained in:
BIN
ControleMachine2/Adrian_Pourchot.tar
Normal file
BIN
ControleMachine2/Adrian_Pourchot.tar
Normal file
Binary file not shown.
39
ControleMachine2/Exercice1.c
Normal file
39
ControleMachine2/Exercice1.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char* suppNonLettres(char* s){
|
||||
int i;
|
||||
for (i=0;i<255;i++){
|
||||
if (s[i]<'A'){
|
||||
s[i]='\a';
|
||||
} if (s[i]>'Z'&& s[i]<'a'){
|
||||
s[i]='\a';
|
||||
} if (s[i]>'z'){
|
||||
s[i]='\a';
|
||||
}
|
||||
} return(s);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
char* s=calloc(256,sizeof(char));
|
||||
char c=-128;
|
||||
int i;
|
||||
int t;
|
||||
|
||||
s[0]=c;
|
||||
for (i=0;i<255;i++){
|
||||
c++;
|
||||
s[i]=c;
|
||||
} suppNonLettres(s);
|
||||
printf("%s\n",s);
|
||||
t=strlen(s);
|
||||
for (i=t;i>=0;i--){
|
||||
if (s[i]=='\a'){
|
||||
t--;
|
||||
}
|
||||
}
|
||||
printf("Cette chaine est de taille %d.\n",t);
|
||||
return 0;
|
||||
}
|
||||
65
ControleMachine2/Exercice2.c
Normal file
65
ControleMachine2/Exercice2.c
Normal file
@@ -0,0 +1,65 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void afficheTab(float tab[],int taille){
|
||||
if(taille==0){
|
||||
return;
|
||||
} afficheTab(tab, taille-1);
|
||||
printf("%.2f ",tab[taille-1]);
|
||||
}
|
||||
|
||||
int indicePlusPetit(float tab[10]){
|
||||
int taille=10;
|
||||
int i;
|
||||
int indice=0;
|
||||
int min=tab[0];
|
||||
|
||||
for(i=1;i<taille;i++){
|
||||
if (tab[i]<min){
|
||||
min=tab[i];
|
||||
indice=i;
|
||||
}
|
||||
} return indice;
|
||||
}
|
||||
|
||||
int indicePlusPetitApresI(float tab[10],int indice){
|
||||
int taille=10;
|
||||
int i;
|
||||
int indice2=indice;
|
||||
int min=tab[indice];
|
||||
|
||||
for(i=indice;i<taille;i++){
|
||||
if (tab[i]<min){
|
||||
min=tab[i];
|
||||
indice2=i;
|
||||
}
|
||||
} return indice2;
|
||||
}
|
||||
|
||||
void echange2cases(float tab[10],int indice1,int indice2){
|
||||
float temp;
|
||||
temp=tab[indice1];
|
||||
tab[indice1]=tab[indice2];
|
||||
tab[indice2]=temp;
|
||||
}
|
||||
|
||||
void triParSelection(float tab[10]){
|
||||
int taille=10;
|
||||
int i;
|
||||
echange2cases(tab,indicePlusPetit(tab),0);
|
||||
for (i=1;i<taille;i++){
|
||||
echange2cases(tab,indicePlusPetitApresI(tab,i),i);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
float tab[10]={43.8,17.0,212.12,251.7,891.18,78.0,182.0,526.19,98.1,290.0};
|
||||
|
||||
afficheTab(tab,10);
|
||||
putchar('\n');
|
||||
triParSelection(tab);
|
||||
afficheTab(tab,10);
|
||||
putchar('\n');
|
||||
return 0;
|
||||
}
|
||||
52
ControleMachine2/Exercice4.c
Normal file
52
ControleMachine2/Exercice4.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct maillon {
|
||||
int valeur;
|
||||
struct maillon* suiv;
|
||||
};
|
||||
|
||||
typedef struct maillon maillon;
|
||||
|
||||
maillon* ajouteDebut(maillon *chaine, int entier){
|
||||
maillon *nouveauMaillon=malloc(sizeof(maillon));
|
||||
nouveauMaillon->valeur=entier;
|
||||
nouveauMaillon->suiv=chaine;
|
||||
return nouveauMaillon;
|
||||
}
|
||||
|
||||
void afficheListe(maillon *chaine){
|
||||
maillon *affichage=malloc(sizeof(maillon));
|
||||
affichage=chaine;
|
||||
while(affichage->suiv!=NULL){
|
||||
printf("%hu ",affichage->valeur);
|
||||
affichage=affichage->suiv;
|
||||
} printf("\n\n");
|
||||
free(affichage);
|
||||
}
|
||||
|
||||
maillon* fusionImperative(maillon *chaine1, maillon *chaine2){
|
||||
int i;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
maillon *liste1=malloc(sizeof(maillon));
|
||||
maillon *liste2=malloc(sizeof(maillon));
|
||||
int i;
|
||||
|
||||
for(i=30;i>=0;i--){
|
||||
if (i%2==1){
|
||||
if (i<=24 && i%9==0){
|
||||
liste1=ajouteDebut(liste1,i);
|
||||
} else{
|
||||
liste2=ajouteDebut (liste2,i);
|
||||
}
|
||||
}else{
|
||||
liste1=ajouteDebut (liste1,i);
|
||||
}
|
||||
} afficheListe(liste1);
|
||||
afficheListe(liste2);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user