Added td5
This commit is contained in:
parent
ff6cdd1208
commit
93f98c6bd4
7 changed files with 527 additions and 0 deletions
48
td5/cestpartitd.cbp
Executable file
48
td5/cestpartitd.cbp
Executable file
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="cestpartitd" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/cestpartitd" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/cestpartitd" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
</Compiler>
|
||||
<Unit filename="exo3" />
|
||||
<Unit filename="exo3.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="exo4.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="main.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
12
td5/cestpartitd.depend
Executable file
12
td5/cestpartitd.depend
Executable file
|
@ -0,0 +1,12 @@
|
|||
# depslib dependency file v1.0
|
||||
1605281467 source:c:\users\alzyohan\desktop\td5\cestpartitd\main.c
|
||||
<stdio.h>
|
||||
|
||||
1605278983 source:c:\users\alzyohan\desktop\td5\cestpartitd\exo3.c
|
||||
<stdio.h>
|
||||
|
||||
1605281487 source:c:\users\alzyohan\desktop\td5\cestpartitd\exo4.c
|
||||
|
||||
1605281606 source:c:\users\alzyohan\desktop\cours en cours\info\td5\cestpartitd\exo4.c
|
||||
<stdio.h>
|
||||
|
20
td5/cestpartitd.layout
Executable file
20
td5/cestpartitd.layout
Executable file
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="exo3.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="189" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="exo4.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="904" topLine="36" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="main.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="3" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
63
td5/exo3.c
Executable file
63
td5/exo3.c
Executable file
|
@ -0,0 +1,63 @@
|
|||
#include <stdio.h>
|
||||
int trouve_min(int N, int tab_entier[]);
|
||||
int trouve_maxi(int N, int tab_entier[]);
|
||||
void trouve_min_max(int N, int tab_entier[],int* mini,int* maxi);
|
||||
|
||||
int exo3(void)
|
||||
{
|
||||
int i, taille=0;
|
||||
int mini, maxi;
|
||||
do
|
||||
{
|
||||
printf("Entrer la taille du tableau : ");
|
||||
scanf("%d",&taille);
|
||||
}while(taille<1);
|
||||
|
||||
int tab[taille];
|
||||
|
||||
for(i=0; i<taille; i++)
|
||||
{
|
||||
printf("\nEntrer un entier : ");
|
||||
scanf("%d",&tab[i]);
|
||||
}
|
||||
|
||||
trouve_min_max(taille, &tab[0], &mini, &maxi);
|
||||
printf("\nLe minimum est : %d",mini);
|
||||
printf("\nLe maximum est : %d",maxi);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void trouve_min_max(int N, int tab_entier[],int* mini,int* maxi)
|
||||
{
|
||||
*mini = trouve_min(N, &tab_entier[0]);
|
||||
*maxi = trouve_maxi(N, &tab_entier[0]);
|
||||
}
|
||||
|
||||
int trouve_maxi(int N, int tab_entier[])
|
||||
{
|
||||
int maxi=tab_entier[0], i;
|
||||
for (i=1; i<N; i++)
|
||||
{
|
||||
if(tab_entier[i] > maxi)
|
||||
{
|
||||
maxi = tab_entier[i];
|
||||
}
|
||||
}
|
||||
|
||||
return maxi;
|
||||
}
|
||||
|
||||
int trouve_min(int N, int tab_entier[])
|
||||
{
|
||||
int mini=tab_entier[0], i;
|
||||
for (i=1; i<N; i++)
|
||||
{
|
||||
if(tab_entier[i] < mini)
|
||||
{
|
||||
mini = tab_entier[i];
|
||||
}
|
||||
}
|
||||
|
||||
return mini;
|
||||
}
|
||||
|
77
td5/exo4.c
Executable file
77
td5/exo4.c
Executable file
|
@ -0,0 +1,77 @@
|
|||
#include <stdio.h>
|
||||
void select(int* tableau);
|
||||
int compter_zero(int tableau[]);
|
||||
int compter_un(int tableau[]);
|
||||
void compter_N(int tableau[]);
|
||||
|
||||
int exo4(void)
|
||||
{
|
||||
int tab[10];
|
||||
select(&tab[0]);
|
||||
//zero=compter_zero(&tab[0]);
|
||||
//printf("Il y a %d zeros dans le tableau",zero);
|
||||
compter_N(tab); // tab ou &tab[0] donnent la même chose.
|
||||
return 0;
|
||||
}
|
||||
|
||||
void select(int* tableau)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<10; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
printf("\nEntrez 10 nombres :");
|
||||
scanf("%d",&tableau[i]);
|
||||
}
|
||||
while(tableau[i]< -5 || tableau[i]> 5);
|
||||
};
|
||||
}
|
||||
|
||||
int compter_zero(int tableau[])
|
||||
{
|
||||
int i;
|
||||
int nbr = 0;
|
||||
for(i=0; i<10; i++)
|
||||
{
|
||||
if(tableau[i]==0)
|
||||
{
|
||||
nbr = nbr+1;
|
||||
};
|
||||
};
|
||||
return nbr;
|
||||
}
|
||||
|
||||
int compter_un(int tableau[])
|
||||
{
|
||||
int i;
|
||||
int nbr = 0;
|
||||
for(i=0; i<10; i++)
|
||||
{
|
||||
if(tableau[i]==1 || tableau[i]==-1)
|
||||
{
|
||||
nbr = nbr+1;
|
||||
};
|
||||
};
|
||||
return nbr;
|
||||
}
|
||||
|
||||
void compter_N(int tableau[])
|
||||
{
|
||||
int i;
|
||||
int nbr = 0;
|
||||
int x;
|
||||
for(x=0; x<=5; x++)
|
||||
{
|
||||
for(i=0; i<10; i++)
|
||||
{
|
||||
if(tableau[i]==x || tableau[i]==-x)
|
||||
{
|
||||
nbr = nbr+1;
|
||||
};
|
||||
};
|
||||
printf("\nIl y a %d [%d,-%d]",nbr,x,x);
|
||||
nbr=0;
|
||||
};
|
||||
}
|
||||
|
306
td5/exos_correc.c
Executable file
306
td5/exos_correc.c
Executable file
|
@ -0,0 +1,306 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
// INTRODUCTION
|
||||
/*
|
||||
int main()
|
||||
{
|
||||
int N;
|
||||
printf("Entrer la taille du tableau\n");
|
||||
scanf("%d",&N);
|
||||
|
||||
int tableau_entiers[N];
|
||||
|
||||
int i;
|
||||
|
||||
for(i=0;i<=(N-1);i++)
|
||||
{
|
||||
tableau_entiers[i] = 2*i +4 ;
|
||||
}
|
||||
|
||||
|
||||
for(i=0;i<=(N-1);i++)
|
||||
{
|
||||
printf("\n\n tableau[%d] vaut %d et est a l'adresse %p", i, tableau_entiers[i], &tableau_entiers[i] );
|
||||
//printf("\n*(tableau+%d) vaut %d et est a l'adresse %p", i, *(tableau_entiers+i), tableau_entiers+i );
|
||||
// tableau_entiers se comporte comme un pointeur qui vaudrait &tableau_entiers[0]
|
||||
}
|
||||
|
||||
|
||||
char tableau_caracteres[N];
|
||||
|
||||
for(i=0;i<=(N-1);i++)
|
||||
{
|
||||
tableau_caracteres[i] = 'a' + i ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
printf("\n**** Meme chose avec des caracteres **** \n");
|
||||
for(i=0;i<=(N-1);i++)
|
||||
{
|
||||
printf("\n\n tableau[%d] vaut %c et est a l'adresse %p", i, tableau_caracteres[i], &tableau_caracteres[i] );
|
||||
printf("\n*(tableau+%d) vaut %c et est a l'adresse %p", i, *(tableau_caracteres+i), tableau_caracteres+i );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
// EXO 1
|
||||
/*
|
||||
# define MAX_TAB 5
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int tab[3];
|
||||
int tab2[MAX_TAB] = {56,4,8};
|
||||
char tab3[1];
|
||||
char tab4[]= {'S','O','S'};
|
||||
|
||||
tab[0] = 1;
|
||||
tab[1] = 9;
|
||||
tab[2] = tab[1]*3;
|
||||
|
||||
printf("tab2[0] = %d\n", tab2[0]);
|
||||
|
||||
tab2[1] = tab2[2]/tab2[1];
|
||||
printf("tab2[1] = %d\n", tab2[1]);
|
||||
|
||||
tab3[0] = 'K';
|
||||
|
||||
tab4[2] = tab3[0]+1;
|
||||
printf("tab4[2] = %c\n", tab4[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
// EXO 2
|
||||
/*
|
||||
int main()
|
||||
{
|
||||
int N=26;
|
||||
char alphabet[N];
|
||||
|
||||
int i;
|
||||
for(i=0;i<=(N-1);i++)
|
||||
{
|
||||
alphabet[i] = 'A' + i ;
|
||||
}
|
||||
|
||||
for(i=0;i<=(N-1);i++)
|
||||
{
|
||||
printf("\n\n alphabet[%d] vaut %c et est a l'adresse %p", i, alphabet[i], &alphabet[i] );
|
||||
//printf("\n*(tableau+%d) vaut %c et est a l'adresse %p", i, *(tableau_caracteres+i), tableau_caracteres+i );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// EXO 3
|
||||
/*
|
||||
int trouve_min(int N, int tab_entier[]); // int trouve_min(int N, int* tab_entier);
|
||||
int trouve_max(int N, int tab_entier[]);
|
||||
void trouve_min_max(int N, int tab_entier[], int* p_mini, int* p_maxi);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, taille;
|
||||
int mini, maxi;
|
||||
|
||||
do
|
||||
{
|
||||
printf("Entrer la taille du tableau : ");
|
||||
scanf("%d",&taille);
|
||||
}
|
||||
while(taille<1);
|
||||
|
||||
int tab[taille];
|
||||
|
||||
// note sur comment avoir l'adresse du premier elmt d'un tableau
|
||||
// question 3 dans le poly
|
||||
printf("\ntab = %p est aussi &tab[0] = %p, &tab = %p\n\n",tab,&tab[0],&tab);
|
||||
|
||||
|
||||
for(i=0; i<taille; i++)
|
||||
{
|
||||
printf("\nEntrer un entier : ");
|
||||
scanf("%d",&tab[i]);
|
||||
}
|
||||
|
||||
mini = trouve_min(taille, &tab[0]); // equivalent a mini = trouve_min(taille, tab)
|
||||
// "tab"
|
||||
printf("\nLe minimum est : %d",mini);
|
||||
|
||||
// question 5
|
||||
maxi = trouve_max(taille, &tab[0]);
|
||||
printf("\nLe maximum est : %d",maxi);
|
||||
|
||||
// question 6
|
||||
// void trouve_min_max(int N, int tab_entier[], int* p_mini, int* p_maxi)
|
||||
trouve_min_max(taille, &tab[0],&mini,&maxi);
|
||||
printf("\n\ntouve par la fonction de la question 6");
|
||||
printf("mini = %d maxi = %d",mini, maxi);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int trouve_min(int N, int tab_entier[]) // int trouve_min(int N, int *tab_entier) {
|
||||
{
|
||||
int mini = tab_entier[0], i;
|
||||
|
||||
for(i=1; i<N; i++)
|
||||
{
|
||||
if (tab_entier[i] < mini)
|
||||
{
|
||||
mini = tab_entier[i] ;
|
||||
}
|
||||
}
|
||||
|
||||
return mini;
|
||||
}
|
||||
|
||||
// question 5
|
||||
int trouve_max(int N, int tab_entier[]) // int trouve_min(int N, int *tab_entier) {
|
||||
{
|
||||
int maxi = tab_entier[0], i;
|
||||
|
||||
for(i=1; i<N; i++)
|
||||
{
|
||||
if (tab_entier[i] > maxi)
|
||||
{
|
||||
maxi = tab_entier[i] ;
|
||||
}
|
||||
}
|
||||
|
||||
return maxi;
|
||||
}
|
||||
|
||||
// question 6
|
||||
void trouve_min_max(int N, int tab_entier[], int* p_mini, int* p_maxi)
|
||||
{
|
||||
*p_mini = trouve_min(N, &tab_entier[0]);
|
||||
*p_maxi = trouve_max(N, &tab_entier[0]);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// EXO 4
|
||||
/*
|
||||
void saisie_tableau(int taille, int tableau_int[]);
|
||||
// int* pointeur_tableau
|
||||
|
||||
int compter_X(int X, int taille, int tableau_int[]);
|
||||
void comter_plus_ou_moins_X(int X, int taille, int tableau_int[], int* p_nb_X, int* p_nb_moinsX );
|
||||
|
||||
int main()
|
||||
{
|
||||
int N = 10;
|
||||
int tableau[N];
|
||||
|
||||
// saisie du tableau
|
||||
saisie_tableau(N,&tableau[0]);
|
||||
// void saisie_tableau(int taille, int tableau_int[]);
|
||||
//juste pour valider la saisie
|
||||
//int i;
|
||||
//for(i=0;i<N;i++)
|
||||
//{
|
||||
// printf("\n\n sortie de la fonction tab[i] = %d",tableau[i]);
|
||||
//}
|
||||
|
||||
int nombre_de_zeros;
|
||||
nombre_de_zeros = compter_X(0,N,&tableau[0]);
|
||||
|
||||
printf("\n nombre de zeros dans le tableau %d",nombre_de_zeros);
|
||||
|
||||
// question de fin (2 et 3)
|
||||
int test;
|
||||
printf("entrer la valeur a tester");
|
||||
scanf("%d",&test);
|
||||
int nb_plus_test, nb_moins_test;
|
||||
|
||||
comter_plus_ou_moins_X(test, N, &tableau[0], &nb_plus_test, &nb_moins_test);
|
||||
|
||||
printf("\n nombre de plus %d dans le tableau %d",test,nb_plus_test);
|
||||
printf("\n nombre de moins %d dans le tableau %d",test,nb_moins_test);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void saisie_tableau(int taille, int tableau_int[])
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<taille;i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
printf("Entrer la case [%d]",i);
|
||||
scanf("%d",&tableau_int[i]);
|
||||
}while( tableau_int[i]<-5 || tableau_int[i]> 5 );
|
||||
//( !(tableau_int[i]>=-5 && tableau_int[i]<=5) )
|
||||
}
|
||||
}
|
||||
|
||||
int compter_X(int X, int taille, int tableau_int[])
|
||||
{
|
||||
int i;
|
||||
int compteur = 0;
|
||||
|
||||
for(i=0;i<taille;i++)
|
||||
{
|
||||
if(tableau_int[i] == X)
|
||||
{
|
||||
compteur++;
|
||||
}
|
||||
}
|
||||
return compteur;
|
||||
}
|
||||
|
||||
void comter_plus_ou_moins_X(int X, int taille, int tableau_int[], int* p_nb_X, int* p_nb_moinsX)
|
||||
{
|
||||
*p_nb_X = compter_X( X,taille,&tableau_int[0]);
|
||||
*p_nb_moinsX = compter_X(-X,taille,&tableau_int[0]);
|
||||
}
|
||||
*/
|
||||
|
||||
// EXO 5
|
||||
|
||||
//void saisir_tab_char(int taille,char tableau[]);
|
||||
void saisir_tab_char(int taille,char* tableau);
|
||||
|
||||
int main()
|
||||
{
|
||||
char tableau_carac[4];
|
||||
saisir_tab_char(3,&tableau_carac[0]);
|
||||
// tableau_carac
|
||||
int i;
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
//printf("%c",tableau_carac[i]);
|
||||
printf("%c",*(tableau_carac+i));
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//void saisir_tab_char(int taille,char tableau[])
|
||||
void saisir_tab_char(int taille,char* tableau)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
//scanf("%c",&tableau[i]); // tableau[i] = getchar();
|
||||
scanf("%c",tableau+i);
|
||||
while(getchar()!='\n'){;} // fflush(stdin);
|
||||
}
|
||||
}
|
1
td5/main.c
Executable file
1
td5/main.c
Executable file
|
@ -0,0 +1 @@
|
|||
|
Loading…
Add table
Reference in a new issue