debut TP16

This commit is contained in:
2023-11-07 17:30:28 +01:00
parent 3d18e26fd9
commit 940fdfe265
12 changed files with 129 additions and 3 deletions

BIN
DEV1.1/TP15/miroir Executable file

Binary file not shown.

View File

@@ -4,19 +4,23 @@
int remplissage( int tab[10]){ int remplissage( int tab[10]){
int tour,signe; int tour,signe;
int tab_temp[2];
srand(time(NULL)); srand(time(NULL));
for (tour=0;tour<10;tour++){ for (tour=0;tour<10;tour++){
tab[tour]=rand()%51; tab[tour]=rand()%51;
int tab_temp[2]={tab[tour],tab[tour]*(-1)}; tab_temp[0]=tab[tour];
tab_temp[1]=tab[tour]*(-1);
signe=rand()%2; signe=rand()%2;
tab[tour]=tab_temp[signe]; tab[tour]=tab_temp[signe];
} }
return *tab;
} }
int inversion(const int tab[10], int tab_inv[10]){ int inversion(const int tab[10], int tab_inv[10]){
int tour; int tour;
for (tour=0;tour<10;tour++) for (tour=0;tour<10;tour++)
tab_val[tour]=tab[(9-tour)]; tab_inv[tour]=tab[(9-tour)];
return *tab_inv;
} }
void affichage( int tab[10]){ void affichage( int tab[10]){
@@ -33,11 +37,12 @@ void affichage( int tab[10]){
for (tour=0;tour<10;tour++) for (tour=0;tour<10;tour++)
printf("-----+"); printf("-----+");
printf("\n"); printf("\n");
}
int main(void) { int main(void) {
int tab[10]; int tab[10];
remplissage(tab);
int tab_inv[10]; int tab_inv[10];
remplissage(tab);
inversion(tab,tab_inv); inversion(tab,tab_inv);
affichage(tab); affichage(tab);
printf("\n"); printf("\n");

BIN
DEV1.1/TP15/zero Executable file

Binary file not shown.

18
DEV1.1/TP15/zero.c Normal file
View File

@@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
int zero(double a) {
a = 0.0;
return a;
}
int main(void) {
double x=37.5;
printf("avant : %f\n", x);
x=zero(x);
printf("après : %f\n", x);
return EXIT_SUCCESS;
}
/*Elle ne fait pas son travaille car la fonction ne renvoie
rien et que la valeur 0 n'est pas atribuées*/

BIN
DEV1.1/TP16/binomial Executable file

Binary file not shown.

47
DEV1.1/TP16/binomial.c Normal file
View File

@@ -0,0 +1,47 @@
/* fichier debogueur1.c : exemple a deboguer */
#include <stdio.h>
#include <stdlib.h>
/* fonction principale */
int main(void) {
int i=-1, j=0, n, k, mem[100];
/* invite */
printf("Calcul de C(n, k) :\n");
/* saisie de n */
printf("Entrez n : ");
scanf("%d", &n);
while((n>100)||(n<1)) {
printf("n doit être compris entre 1 et 100 !\n");
printf("Entrez n : ");
scanf("%d", &n);
}
/* saisie de k */
printf("Entrez k : ");
scanf("%d", &k);
while((k>n)||(k<1)) {
printf("k doit être compris entre 1 et %d !\n", n);
printf("Entrez k : ");
scanf("%d", &k);
}
/* calculs... */
while (i<n) {
if(j<1) {
*(mem+(j=i++)+1) = 1;
} else {
*(mem+j--) += *(mem+j);
}
}
/* affichage du resultat */
printf("C(%d, %d) = %d\n", n, k,j-i);
return EXIT_SUCCESS;
}
/* fin du fichier debogueur1.c */

BIN
DEV1.1/TP16/etape Executable file

Binary file not shown.

20
DEV1.1/TP16/etape.c Normal file
View File

@@ -0,0 +1,20 @@
#include <stdlib.h>
#include <stdio.h>
int main(void) {
int a = 1, b = 2, c = 3;
int *p, *q;
p=&a;
q=&c;
*p=(*q)++;
p=q;
q=&b;
*p-=*q;
++*q;
*p*=*q;
a=++*q**p;
p=&a;
*q=*p/(*q);
return EXIT_SUCCESS;
}

BIN
DEV1.1/TP16/tutoriel Executable file

Binary file not shown.

16
DEV1.1/TP16/tutoriel.c Normal file
View File

@@ -0,0 +1,16 @@
#include <stdlib.h>
#include <stdio.h>
int somme(int n, int m) {
return n+m;
}
int main(void) {
int valeur;
int* p = &valeur;
printf("Entrez un entier : ");
scanf("%d", p);
printf("Le double vaut %d\n", somme(*p, *p));
return EXIT_SUCCESS;
}

BIN
DEV1.1/TP16/tutoriel2 Executable file

Binary file not shown.

20
DEV1.1/TP16/tutoriel2.c Normal file
View File

@@ -0,0 +1,20 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void envers(const char texte[]) {
int position;
for(position = strlen(texte)-1; position >= 0; position--) {
printf("%c", texte[position]);
}
printf("\n");
}
int main(int argc, char** argv) {
if (argc < 2) {
printf("usage : %s <texte>\n", argv[0]);
return EXIT_FAILURE;
}
envers(argv[1]);
return EXIT_SUCCESS;
}