Advertisement
ripper2hl

Invertir arreglo

Jun 14th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.41 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int x,y,i,j,num=1,b,m,n,contador=1,media;
  5.     printf("cuantas filas\n");
  6.     scanf("%d",&x);
  7.     printf("Cuantas columnas\n");
  8.     scanf("%d",&y);
  9.     media=(x*y)/2;
  10.     m=x-1;
  11.     n=y-1;
  12.     int arreglo[x][y];
  13.     for(i=0;i<x;i++)
  14.     {
  15.                      for(j=0;j<y;j++)
  16.                      {
  17.                                       arreglo[i][j]=num++;
  18.                       }
  19.                      }
  20.     printf("\nImpresion de la matriz\n\n");
  21.     for(i=0;i<x;i++)
  22.     {
  23.          for(j=0;j<y;j++)
  24.          {
  25.                           printf("%d\t",arreglo[i][j]);
  26.           }
  27.           printf("\n");
  28.      }
  29.      for(i=0;contador<=media;i++)/* invertir la matriz*/
  30.     {
  31.                      for(j=0;j<y;j++)
  32.                      {
  33.                                       b=arreglo[i][j];
  34.                                       arreglo[i][j]=arreglo[m][n];
  35.                                       arreglo[m][n]=b;
  36.                                       n--;
  37.                                       contador++;
  38.                       }
  39.                       n=y-1;
  40.                       m--;
  41.                      }
  42.      printf("\nImpresion de la matriz invertida\n\n");
  43.     for(i=0;i<x;i++)
  44.     {
  45.          for(j=0;j<y;j++)
  46.          {
  47.                           printf("%d\t",arreglo[i][j]);
  48.           }
  49.           printf("\n");
  50.      }
  51.     getch();
  52.     return(0);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement