Glaas2

exa1

Jun 4th, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.99 KB | None | 0 0
  1. /////////////////////// EXA 2 ///////////////////////////////
  2. #include "stdafx.h"
  3. #include <stdlib.h>
  4.  
  5. #define TAM_MAX 5
  6. #define TAM_ABC 26
  7.  
  8. void generarA(char a[], int &tam);
  9. int contar(char a[], int f[], int tam);
  10. void inicializar_F(int f[]);
  11. void generarC(char c[], char a[], int tam, int pos);
  12.  
  13. int main()
  14. {
  15.     int TAM, F[TAM_ABC], i;
  16.     char A[TAM_MAX], C[TAM_MAX];
  17.     int letra;
  18.  
  19.     generarA(A, TAM);
  20.     puts(A);
  21.     inicializar_F(F);
  22.     letra = contar(A, F, TAM);
  23.     /***********/
  24.     for (i = 0;i<TAM_ABC;i++)
  25.         printf("%c ", i+65);
  26.     printf("\n");
  27.     /********/
  28.     for (i = 0;i<TAM_ABC;i++)
  29.         printf("%d ", F[i]);
  30.     printf("\n");
  31.     /********/
  32.     generarC(C, A, TAM, letra);
  33.  
  34.  
  35.     return 0;
  36. }
  37.  
  38. void generarA(char a[], int &tam)
  39. {
  40.     int i;
  41.     tam = 12;//rand()%TAM_MAX;
  42.     for (i = 0; i<tam; i++)
  43.         a[i] = rand() % (90 - 65 + 1) + 65;
  44.     a[i] = '\0';
  45. }
  46.  
  47. void inicializar_F(int f[])
  48. {
  49.     int i;
  50.     for (i = 0;i<TAM_ABC;i++)
  51.         f[i] = 0;
  52. }
  53.  
  54. int contar(char a[], int f[], int tam)
  55. {
  56.     int i, mayor;
  57.  
  58.  
  59.     for (i = 0;i<tam;i++)
  60.     {
  61.  
  62.         switch (a[i])
  63.         {
  64.         case 'A': f[0] = f[0] + 1; break;
  65.         case 'B': f[1] = f[1] + 1; break;
  66.         case 'C': f[2] = f[2] + 1; break;
  67.         case 'D': f[3] = f[3] + 1; break;
  68.         case 'E': f[4] = f[4] + 1; break;
  69.         case 'F': f[5] = f[5] + 1; break;
  70.         case 'G': f[6] = f[6] + 1; break;
  71.         case 'H': f[7] = f[7] + 1; break;
  72.         case 'I': f[8] = f[8] + 1; break;
  73.         case 'J': f[9] = f[9] + 1; break;
  74.         case 'K': f[10] = f[10] + 1; break;
  75.         case 'L': f[11] = f[11] + 1; break;
  76.         case 'M': f[12] = f[12] + 1; break;
  77.         case 'N': f[13] = f[13] + 1; break;
  78.         case 'O': f[14] = f[14] + 1; break;
  79.         case 'P': f[15] = f[15] + 1; break;
  80.         case 'Q': f[16] = f[16] + 1; break;
  81.         case 'R': f[17] = f[17] + 1; break;
  82.         case 'S': f[18] = f[18] + 1; break;
  83.         case 'T': f[19] = f[19] + 1; break;
  84.         case 'U': f[20] = f[20] + 1; break;
  85.         case 'V': f[21] = f[21] + 1; break;
  86.         case 'W': f[22] = f[22] + 1; break;
  87.         case 'X': f[23] = f[23] + 1; break;
  88.         case 'Y': f[24] = f[24] + 1; break;
  89.         case 'Z': f[25] = f[25] + 1; break;
  90.         }
  91.  
  92.     }
  93.  
  94.     mayor = f[0];
  95.     for (i = 0;i<TAM_ABC;i++)
  96.         if (f[i]>mayor)
  97.             mayor = i;
  98.  
  99.     return mayor;
  100. }
  101.  
  102.  
  103. void generarC(char c[], char a[], int tam, int pos)
  104. {
  105.     int i=0, j=0;
  106.  
  107.     for (i = 0,j=0;i<tam;i++,j++)
  108.     {
  109.         c[i] = a[j];
  110.         if (c[i] == char(pos + 65))
  111.             c[i] = a[++j];
  112.     }
  113.     c[i] = '\0';
  114.     printf("\n%c\n\n", pos+65);
  115.     puts(c);
  116.  
  117. }
  118. ///////////////////////////////////////////////////////////////
  119.  
  120. // Matriz A[M][N]
  121. //
  122.  
  123. #include "stdafx.h"
  124. #include <stdlib.h>
  125. #include <stdio.h>
  126.  
  127. #define M   4 //  renglones
  128. #define N   3 // columnas
  129.  
  130. int main()
  131. {
  132.     int x, i=0, j=0; // rango aleatorio definido por 0 a x-1; j, i contadores
  133.     int max=0;
  134.     int A[M][N]; // arreglo a llenar con valores aleatorios
  135.     int B[M];  // arreglo para almacenar maximos de los renglones
  136.     bool desorden;
  137.  
  138.  
  139.     printf("\nIngresa X(valor max. aleatorio): ");
  140.     scanf("%d", &x);
  141.  
  142. ////////////////////// Llenado de Matriz /////////////////////////
  143.  
  144.     for(i=0;i<M;i++)        // llenado de la matriz aleatoriamente
  145.         for(j=0;j<N;j++)
  146.             A[i][j]=rand()%x;
  147.  
  148.     printf("\n      Matriz generada\n\n");
  149.     printf("            ");
  150.    
  151.         for(i=0;i<M;i++)
  152.         {
  153.         for(j=0;j<N;j++)
  154.             printf("\t%d  ", A[i][j]);
  155.         printf("\n          ");
  156.         }
  157.  
  158.     printf("\n");
  159. ////////////////////////////////////////////////////////////////////
  160.  
  161. /////////////////// Maximos ////////////////////
  162.  
  163.     printf("\n      Los maximos de cada renglon son:\n\n");
  164.  
  165.     for(i=0;i<M;i++)
  166.     {
  167.        
  168.         for(j=0;j<N;j++)
  169.         {
  170.             if(max<A[i][j])
  171.                 max=A[i][j];
  172.         }  
  173.         B[i]=max;
  174.         max=0;
  175.     }
  176.  
  177.     for(i=0;i<M;i++)
  178.         printf("        \t%d\n", B[i]);
  179.  
  180. //////////////////////////////////////////////////
  181.  
  182.  
  183. //////////////// ordenado de maximos ///////////////
  184.  
  185.  
  186.     printf("\n      Arreglo ordenado\n\n");
  187.          
  188.     for(i=1; i<M; i++)
  189.     {
  190.         for(j=0; j<M-i; j++)
  191.         {
  192.             if(B[j]>B[j+1])
  193.             {
  194.                 max    = B[j+1];
  195.                 B[j+1] = B[j];
  196.                 B[j]   = max;
  197.             }
  198.         }
  199.     }
  200.  
  201.         for(i=0;i<M;i++)
  202.         printf("             %d\n", B[i]);
  203. /////////////////////////////////////////////////
  204.     return 0;
  205. }
Advertisement
Add Comment
Please, Sign In to add comment