Advertisement
cchori

Ejercicio cósmico matriz

Aug 28th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.78 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define FIL 8
  4. #define COL 8
  5.  
  6. void CargaMat(int[][COL]);
  7. void MostrarMat(int[][COL]);
  8. void diagonalprincipal(int[][COL]);
  9. void diagonalsecundaria(int[][COL]);
  10. void triangulosuperiorED(int[][COL]);
  11. void triangulosup(int[][COL]);
  12. void triangulosupsecundario(int[][COL]);
  13. void tianguloinf(int[][COL]);
  14. void mayormatcuadrada(int[][COL]);
  15.  
  16. void main()
  17. {
  18.     int mat[FIL][COL]=  {01,02,03,04,05,06,07,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64};
  19.     char res;
  20.  
  21.     MostrarMat(mat);
  22.  
  23.     printf("\n\nMenu:\na. Diagonal principal.\t\tb.Diagonal secundaria.\nc. Triangulo superior.\t\td. Triangulo inferior.\ne. Triangulo sup d. secundaria.\tf.Triangulo inf. d. secundaria.\ng. Triangulo sup. entre diag.\th. Triangulo der. entre diag.\ni. Triangulo inf. entre diag.\tj. Triangulo izq. entre diag.\nk. Matriz identidad?\t\tl. Diagonal?\nm. Escalar?\t\t\tn. Simetrica?\no. Traspuesta\n");
  24.     printf("Eliga una opcion: ");
  25.     do{
  26.         scanf("%c",&res);
  27.     }while(res!='x'&&res!='a'&&res!='b'&&res!='c'&&res!='d'&&res!='e'&&res!='f'&&res!='g'&&res!='h'&&res!='i'&&res!='j'&&res!='k'&&res!='l'&&res!='m'&&res!='n'&&res!='o');
  28.  
  29.     if(res=='a')
  30.         diagonalprincipal(mat);
  31.  
  32.     if(res=='b')
  33.         diagonalsecundaria(mat);
  34.  
  35.     if(res=='g')
  36.         triangulosuperiorED(mat);
  37.  
  38.     if(res=='c')
  39.         triangulosup(mat);
  40.  
  41.     if(res=='e')
  42.         triangulosupsecundario(mat);
  43.  
  44.     if(res=='d')
  45.         trianguloinf(mat);
  46.  
  47.     if(res=='x')
  48.         mayormatcuadrada(mat);
  49.  
  50.  
  51. }
  52.  
  53. void CargaMat(int mat[][COL])
  54. {
  55.     int i,j;
  56.  
  57.     for(i=0;i<FIL;i++)
  58.     {
  59.         for(j=0;j<COL;j++)
  60.         {
  61.             printf("Ingresar el elemento [%d][%d].",i,j);
  62.             scanf("%d",&mat[i][j]);
  63.         }
  64.     }
  65. }
  66.  
  67. void MostrarMat (int mat[][COL])
  68. {
  69.     int i,j;
  70.  
  71.     printf("\n");
  72.  
  73.     for(i=0;i<FIL;i++)
  74.     {
  75.         for(j=0;j<COL;j++)
  76.         {
  77.             printf("%d\t",mat[i][j]);
  78.         }
  79.  
  80.         printf("\n");
  81.     }
  82. }
  83.  
  84. void diagonalprincipal(int mat[][COL])
  85. {
  86.     int i;
  87.  
  88.     printf("\n");
  89.  
  90.     for(i=0;i<COL;i++)
  91.     {
  92.         printf("%d\t",mat[i][i]);
  93.     }
  94.     printf("\n");
  95. }
  96.  
  97. void diagonalsecundaria(int mat[][COL])
  98. {
  99.     int i,j=COL-1;
  100.  
  101.     printf("\n");
  102.  
  103.     for(i=0;i<FIL;i++)
  104.     {
  105.         printf("%d\t",mat[i][j]);
  106.         j--;
  107.     }
  108.     printf("\n");
  109. }
  110.  
  111. void triangulosuperiorED(int mat[][COL])
  112. {
  113.     int i,j;
  114.  
  115.     printf("\n");
  116.  
  117.     for(i=0;i<FIL/2;i++)
  118.     {
  119.         for(j=1+i;j<COL-1-i;j++)
  120.             printf("%d\t",mat[i][j]);
  121.     }
  122.     printf("\n");
  123. }
  124.  
  125. void triangulosup(int mat [][COL])
  126. {
  127.     int i,j;
  128.  
  129.  
  130.     for(i=0;i<COL-1;i++)
  131.         for(j=i+1;j<COL;j++)
  132.             printf("%d\t",mat[i][j]);
  133. }
  134.  
  135. void triangulosupsecundario(int mat [][COL])
  136. {
  137.     int i,j;
  138.     for(i=0;i<COL-1;i++)
  139.         for(j=0;j<COL-1-i;j++)
  140.             printf("%d\t",mat[i][j]);
  141. }
  142.  
  143. void trianguloinf(int mat[][COL])
  144. {
  145.     int i,j;
  146.  
  147.     for(i=1;i<COL;i++)
  148.         for(j=0;j<i;j++)
  149.             printf("%d\t",mat[i][j]);
  150. }
  151.  
  152. void mayormatcuadrada(int mat[][COL])
  153. {
  154.     int F,C;
  155.  
  156.     printf("Ingrese el valor de fila y columna del elemento: ");
  157.     do{
  158.         scanf("%d%d",&F,&C);
  159.     }while((F<1||F>FIL)||(C<1||C>COL));
  160.    
  161.     if((F-1)==0)
  162.     {
  163.         if((C-1)==0||(C==COL))
  164.             Estaenlaesquina(mat,F,C);
  165.         else
  166.             Contralapare(mat,F,C);
  167.     }
  168.            
  169.     if(F==COL)
  170.     {
  171.         if((C-1)==0||(C==COL))
  172.             Estaenlaesquina(mat,F,C);
  173.         else
  174.             Contralapare(mat,F,C);
  175.     }
  176.            
  177.     if((C-1)==0||C==COL)
  178.     {
  179.         Contralapare(mat,F,C);
  180.     }
  181.     else
  182.         Estaenelmedio(mat,F,C);
  183.        
  184.    
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement