1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| #include <stdio.h>
#include <string.h>
#define ROWS 2
#define COLS 2
int saisie (double tab[][COLS + 1], int rows, int cols);
void affiche (double tab[][COLS + 1], int rows, int cols);
int main (void)
{
double tab[ROWS + 1][COLS + 1] = { 0 };
while (saisie (tab, ROWS, COLS))
{
}
affiche (tab, ROWS, COLS);
return 0;
}
int saisie (double tab[][COLS + 1], int rows, int cols)
{
int continu = 0;
if ((tab != NULL) && (rows > 0) && (cols > 0))
{
int ret, i;
do
{
puts ("entrer i :");
ret = scanf ("%d", &i);
scanf ("%*[^\n]"), getchar ();
}
while ((ret != 1) || (i < -1) || (i >= rows));
if (i == -1)
{
}
else
{
continu = 1;
int j, cpt;
do
{
puts ("entrer j :");
ret = scanf ("%d", &j);
scanf ("%*[^\n]"), getchar ();
}
while ((ret != 1) || (j < 0) || (j >= cols));
do
{
puts ("entrer x :");
ret = scanf ("%lf", &tab[i][j]);
scanf ("%*[^\n]"), getchar ();
}
while (ret != 1);
for (cpt = 0, tab[i][cols] = 0; cpt < cols; cpt++)
{
tab[i][cols] += tab[i][cpt];
}
for (cpt = 0, tab[rows][j] = 0; cpt < rows; cpt++)
{
tab[rows][j] += tab[cpt][j];
}
}
}
return continu;
}
void affiche (double tab[][COLS + 1], int rows, int cols)
{
if ((tab != NULL) && (rows > 0) && (cols > 0))
{
int i, j;
for (i = 0; i <= rows; i++)
{
if (i == rows)
{
puts ("------------------------------------------");
}
for (j = 0; j <= cols; j++)
{
if (j == cols)
{
printf ("| %g\n", tab[i][j]);
}
else
{
printf ("%g ", tab[i][j]);
}
}
}
}
} |
Partager