ajout fichiers

This commit is contained in:
lecorre
2021-09-22 15:12:02 +02:00
parent 84ccdcaa4e
commit f497652e47
15 changed files with 294 additions and 0 deletions

46
TD1/Ex1.c Normal file
View File

@@ -0,0 +1,46 @@
#include <stdlib.h>
#include <stdio.h>
#include "Ex1a.h"
int main(int argc, char const *argv[]) {
int size;
int choix;
int i;
int menu = 1;
printf("Rentrez la taille de la matrice : ");
scanf("%d", &size);
int* mat = malloc((size*size)*sizeof(int));
for(i = 0; i<(size*size); i++) {
scanf("%d", &mat[i]);
}
Afficher(size, mat);
while (menu) {
printf("\n\n1. Multiplication scalaire\n2. Addition\n3. Multiplication\n4. Quitter\n\nChoix : ");
scanf("%d", &choix);
if (choix == 4) {
menu = 0;
} else if (choix == 1) {
MultiplicationScalaire(size, mat);
Afficher(size, mat);
} else if (choix == 2) {
Addition(size, mat);
Afficher(size, mat);
} else if (choix == 3) {
Multiplication(size, mat);
Afficher(size, mat);
}
}
free(mat);
return EXIT_SUCCESS;
}

BIN
TD1/Ex1.o Normal file

Binary file not shown.

40
TD1/Ex1a.c Normal file
View File

@@ -0,0 +1,40 @@
#include <stdlib.h>
#include <stdio.h>
void Afficher(int size, int* mat) {
int i;
printf("\nVoici votre matrice :\n");
for(i = 0; i<size*size;i++) {
if (i%size==0) {
printf("\n");
}
printf("%3d", mat[i]);
}
}
void MultiplicationScalaire(int size, int* mat) {
int i;
int sc;
printf("\nChoisissez un nombre pour multiplier la matrice : ");
scanf("%d", &sc);
for (i = 0; i<(size*size); i++) {
mat[i] = mat[i]*sc;
}
}
void Addition(int size, int* mat) {
int i;
printf("\nCreer la 2éme matrice pour l'addition : \n");
int* mat2 = malloc((size*size)*sizeof(int));
for(i = 0; i<(size*size); i++) {
scanf("%d", &mat2[i]);
}
for (i = 0; i<(size*size); i++) {
mat[i] = mat[i]+mat2[i];
}
free(mat2);
}
void Multiplication(int size, int* mat) {
int i;
}

10
TD1/Ex1a.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef EX1A_H
#define EX1A_H
void Afficher(int size, int* mat) ;
void MultiplicationScalaire(int size, int* mat) ;
void Addition(int size, int* mat);
void Multiplication(int size, int* mat) ;
#endif

21
TD1/Makefile Normal file
View File

@@ -0,0 +1,21 @@
OBJS = Ex1.o Ex1a.c
SRC = %(willcard*.c)
OUT = ex1
CC = gcc
FLAGS = -g -c
LFLAGS =
all: $(OBJS)
$(CC) -g $(OBJS) -o $(OUT) $(LFLAGS) -lgraph
Ex1.o: Ex1.c
$(CC) $(FLAGS) Ex1.c
Ex1a.o: Ex1a.c
$(CC) $(FLAGS) Ex1a.c
clean:
rm -f $(OBJS) $(OUT)