code TP6 et TP7
This commit is contained in:
“[JMF]” 2021-10-21 18:58:25 +02:00
parent 25fe9af023
commit 5015fcc824
6 changed files with 120 additions and 0 deletions

BIN
TP6/a.out Executable file

Binary file not shown.

21
TP6/fonctions.c Normal file
View File

@ -0,0 +1,21 @@
#include <stdio.h>
int main () {
float a = 3.;
float b = 2.;
float norme(float ,float );
printf("%f \n",norme(a,b));
return 1;
}
float norme(float x,float y) {
return x*x+y*y ;
}

16
TP6/lancer.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
int main () {
float x,y;
int n=0; // compteur lancers
int n_disc=0; // nb dans le disque
for(n=0;n<1e6;n=n+1) { // boucle lancers
x = (2*(float)rand())/RAND_MAX - 1.;
y = (2*(float)rand())/RAND_MAX - 1.;
// TEST : dans le carre ?
if(x*x+y*y<1)
n_disc=n_disc+1;
}
printf("approx pi = %f\n",(4.*n_disc)/n);
}

BIN
TP7/a.out Executable file

Binary file not shown.

32
TP7/affiche.c Normal file
View File

@ -0,0 +1,32 @@
#include <stdio.h>
#define N 3
int main () {
// int A[N][N] = {1,2,3,4,5,6,7,8,9}; // Initialisation pas magique
int A[N][N] = {4,2,3,2,3,4,3,4,2}; // Initialisation pas magique
void affiche (int, int tab[N][N]);
affiche(N,A);
return 1;
}
void affiche(int n, int tab[n][n]) { // affiche les 4 elements
int i;
int j;
for(i=0;i<n;i=i+1)
{
for(j=0;j<n;j++)
{
printf("%d\t",tab[i][j]);
}
printf("\n"); // pour sauter de ligne
}
return;
}

51
TP7/echange.c Normal file
View File

@ -0,0 +1,51 @@
#include <stdio.h>
#define N 3
int main () {
// int A[N][N] = {1,2,3,4,5,6,7,8,9}; // Initialisation pas magique
int A[N][N] = {4,2,3,2,3,4,3,4,2}; // Initialisation pas magique
int B[N][N] = {0};
void affiche (int, int tab[N][N]);
void matrice_echange(int, int tab[N][N], int tab2[N][N]);
affiche(N,B);
matrice_echange(N,A,B);
affiche(N,A);
affiche(N,B);
return 1;
}
void matrice_echange(int n, int orig[n][n], int target[n][n])
{
int i;
int j;
for(i=0;i<n;i=i+1)
{
for(j=0;j<n;j++)
{
target[i][j] = orig[i][j];
}
}
return;
}
void affiche(int n, int tab[n][n]) { // affiche les 4 elements
int i;
int j;
for(i=0;i<n;i=i+1)
{
for(j=0;j<n;j++)
{
printf("%d\t",tab[i][j]);
}
printf("\n"); // pour sauter de ligne
}
return;
}