LOVEGUN

Exercice 5 (Série Esprit)

Oct 14th, 2021 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int max (int a,int b)
  5. {
  6.     if (a>b)
  7.     {
  8.         return a;
  9.     }else
  10.     {
  11.         return b;
  12.     }
  13. }
  14. int main()
  15. {
  16.     int m,m1[10][10],m2[10][10],n,o,p,i,j,l,c;
  17.     printf ("Saisir la taille de la première matrice");
  18.     scanf ("%d%d",&m,&n);
  19.     printf ("Saisir la taille de la deuxème matrice");
  20.     scanf ("%d%d",&o,&p);
  21.     for (i=0;i<m;i++)
  22.     {
  23.         for (j=0;j<n;j++)
  24.         {
  25.             printf ("\nM1[%d][%d]: ",i,j);
  26.             scanf ("%d",&m1[i][j]);
  27.         }
  28.     }
  29.     for (i=0;i<o;i++)
  30.     {
  31.         for (j=0;j<p;j++)
  32.         {
  33.             printf ("\nM2[%d][%d]: ",i,j);
  34.             scanf ("%d",&m2[i][j]);
  35.         }
  36.     }
  37.     l=max(m,o);
  38.     c=max(n,p);
  39.     system ("cls");
  40.     printf ("La matrice final est :\n");
  41.     for (i=0;i<l;i++)
  42.     {
  43.         for (j=0;j<c;j++)
  44.         {
  45.             if (i>m-1 || j>n-1)
  46.             {
  47.                 printf ("%d|",m2[i][j]);
  48.             }
  49.             } else if (i>o-1 || j>p-1)
  50.             {
  51.                 printf ("%d|",m1[i][j]);
  52.             }else
  53.             {
  54.                 printf ("%d|",m1[i][j]+m2[i][j]);
  55.             }
  56.         }
  57.         printf ("\n");
  58.     }
  59. }
  60.  
Add Comment
Please, Sign In to add comment