This commit is contained in:
Geoffrey Frogeye 2016-01-27 09:44:08 +01:00
parent 6fc5577666
commit b1fce38fc7
2 changed files with 70 additions and 0 deletions

67
TP1/E10.c Normal file
View file

@ -0,0 +1,67 @@
/* Somme les éléments d'un tableau */
#include <stdio.h>
int main() {
int M, N;
printf("Entrez les dimensions en M du tableau : ");
scanf("%d", &M);
printf("Entrez les dimensions en N du tableau : ");
scanf("%d", &N);
if (M < 1 || M > 50 || N < 1 || N > 50) {
printf("M et N doivent être compris entre 1 et 50");
}
int t[50][50];
int m, n;
for (n = 0; n < N; n++) {
for (m = 0; m < M; m++) {
printf("Entrez la valeur du tableau aux coordonnées (%d, %d) : ", m, n);
scanf("%d", &t[m][n]);
}
}
printf("\n T ");
for (m = 0; m < M; m++) {
printf("");
printf("%3d", m);
}
for (n = 0; n < N; n++) {
// Dessine une ligne
printf("\n───");
for (m = 0; m < M; m++) {
printf("┼───");
}
printf("\n");
printf("%3d", n);
for (m = 0; m < M; m++) {
printf("");
printf("%3d", t[m][n]);
}
}
printf("\n\n");
int S;
// S_L
for (n = 0; n < N; n++) {
S = 0;
for (m = 0; m < M; m++) {
S += t[m][n];
}
printf("S_L[%d] = %d\n", n, S);
}
// S_C
for (m = 0; m < M; m++) {
S = 0;
for (n = 0; n < N; n++) {
S += t[m][n];
}
printf("S_C[%d] = %d\n", m, S);
}
return 0;
}

View file

@ -33,6 +33,9 @@ E8.exe: E8.c
E9.exe: E9.c
gcc E9.c -o E9.exe
E10.exe: E10.c
gcc E10.c -o E10.exe
.PHONY: all clean
clean: