Advertisement
Jessfelicout

Untitled

Jun 17th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.34 KB | None | 0 0
  1. /*Questão 2 - final de 2013.1*/
  2.  
  3. #include<stdio.h>
  4.  
  5. void ImprimeMatriz(int matriz[][50], int m, int n)
  6. {
  7.     int i,j, cont=1;
  8.  
  9.     for(i=0; i<m; i++)
  10.     {
  11.         for(j=0; j<n; j++)
  12.         {
  13.             if(j=0 || matriz[i][j-1]==-1)
  14.                 matriz[i][j]=cont;
  15.  
  16.               if(j>0)
  17.                 {   if(matriz[i][j]==0 && matriz[i][j-1]==0)
  18.                         matriz[i][j]=cont;
  19.                 }
  20.  
  21.              if(matriz[i][j]==matriz[i][j]);
  22.                     cont--;
  23.         }
  24.  
  25.         cont++;
  26.  
  27.     }
  28.  
  29. printf("Matriz de saida:\n");
  30.  
  31.     for(i=0; i<m; i++)
  32.     {
  33.         for(j=0; j<n; j++)
  34.         printf("%d ",matriz[i][j]);
  35.  
  36.         printf("\n");
  37.     }
  38.  
  39.  
  40. }
  41.  
  42.  
  43. void CarregarMatriz(int matr[][50], int linhas, int colunas)
  44. {
  45.     int i,j;
  46.  
  47.  for(i=0; i<linhas; i++)
  48.     {   printf("Informe as posicoes (0 ou -1) da %da linha:\n", i+1);
  49.  
  50.             for(j=0; j<colunas; j++)
  51.                 scanf("%d",&matr[i][j]);
  52.  
  53.             printf("\n");
  54.     }
  55.  
  56.  ImprimeMatriz(matr, linhas, colunas);
  57.  
  58. }
  59.  
  60. int main ()
  61. {
  62.     int mat [50][50], i,j, l,c;
  63.  
  64.  
  65.     do{
  66.         printf("Informe as dimennsoes lxc da matriz:\nl:");
  67.         scanf("%d", &l);
  68.         printf("\nc:");
  69.         scanf("%d",c);
  70.         printf("\n");
  71.  
  72.         }while(l>50 || c>50);
  73.  
  74.     CarregarMatriz(mat, l,c);
  75.  
  76.  
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement