ajout fichiers
This commit is contained in:
46
TD1/Ex1.c
Normal file
46
TD1/Ex1.c
Normal 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;
|
||||
}
|
40
TD1/Ex1a.c
Normal file
40
TD1/Ex1a.c
Normal 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
10
TD1/Ex1a.h
Normal 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
21
TD1/Makefile
Normal 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)
|
Reference in New Issue
Block a user