Advertisement
lButcherl

Matriz 02

Nov 1st, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. /*2. Faça um algoritmo que leia uma matriz de dimensão 3 x 3 e apresente na tela o maior e o menor elemento
  2. da matriz.*/
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #define tam 3
  7.  
  8. main()
  9. {
  10.       int i,j,mata[tam][tam],maior,menor;
  11.       for (i = 0; i < tam; i++)
  12.       {
  13.           for (j = 0; j < tam; j++)
  14.           {
  15.               printf("Informe o numero: ");
  16.               scanf("%i", &mata[i][j]);
  17.               if ( i == 0 && j == 0)
  18.               {
  19.                    maior = mata [i][j];
  20.                    menor = mata [i][j];
  21.               }
  22.               else if (mata[i][j] > maior)
  23.               {
  24.                               maior = mata[i][j];
  25.                   }
  26.                   if (mata[i][j] < menor)
  27.                   {
  28.                                  menor = mata[i][j];
  29.                   }                  
  30.           }
  31.       }
  32.       printf("Maior  = %i || Menor = %i\n",maior,menor);
  33.  
  34.               system("pause");
  35.               }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement