GatoBooster

Cuestionario 3 preg 3

Sep 12th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.98 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.  
  5. int matriz[10][10] = {};
  6. int filas = 0;
  7. int columnas = 0;
  8. int i;
  9. int j;
  10. int matrizRotada[10][10] = {};
  11. int angulo = 0;
  12. int k;
  13.  
  14. scanf("%d%d",&filas,&columnas);
  15.  
  16. scanf("%d",&angulo);
  17.  
  18. for(i = 0; i < filas;i++){
  19.     for(j = 0; j < columnas;j++){
  20.         scanf("%d",&matriz[i][j]);
  21.     }
  22. }
  23.  
  24. if(angulo % 90 != 0 ){
  25.     printf("Angulo no valido");
  26.     return 0;
  27. }
  28.  
  29. while(angulo > 360){
  30.     angulo = angulo - 360;
  31.     }
  32.  
  33.  
  34. k = columnas - 1;
  35.  
  36. if(angulo == 90) {
  37.     for(i = 0; i < columnas;i++) {
  38.         for(j = 0; j < filas; j++) {
  39.             matrizRotada[i][j] = matriz[j][k];
  40.         }
  41.         k--;
  42.     }
  43.  
  44. for(i= 0;i < columnas;i++) {
  45.     for(j = 0; j < filas;j++) {
  46.         printf("%d ",matrizRotada[i][j]);
  47.     }
  48.     printf("\n");
  49. }
  50.  
  51. }
  52. else{
  53.     if(angulo == 180) {
  54.         for(i = 0; i < filas;i++) {
  55.             for(j = 0; j < columnas; j++) {
  56.                 matrizRotada[i][j] = matriz[filas-i-1][columnas-j-1];
  57.             }
  58.         }  
  59.         for(i= 0;i < filas;i++) {
  60.             for(j = 0; j < columnas;j++) {
  61.                 printf("%d ",matrizRotada[i][j]);
  62.             }
  63.             printf("\n");
  64.         }
  65.     }
  66.     else{
  67.         k = columnas - 1;
  68.         if(angulo == 270) {
  69.             for(i = 0; i < columnas;i++) {
  70.                 k = 0;
  71.                 for(j = (filas - 1); j >= 0; j--) {
  72.                     matrizRotada[i][k] = matriz[j][i];
  73.                     k++;
  74.                 }
  75.                 k--;
  76.             }  
  77.             for(i= 0;i < columnas;i++) {
  78.                 for(j = 0; j < filas;j++) {
  79.                     printf("%d ",matrizRotada[i][j]);
  80.                 }
  81.                 printf("\n");
  82.             }
  83.         }
  84.         else{
  85.             for(i= 0;i < filas;i++) {
  86.                 for(j = 0; j < columnas;j++) {
  87.                 printf("%d ",matriz[i][j]);
  88.                 }
  89.                 printf("\n");
  90.             }
  91.         }
  92.     }
  93. }
  94.  
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment