All pastes #84500 Raw Edit

coyo

public c v1 · immutable
·published 2006-07-11 00:04 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <time.h>#if defined DJGPP || defined __TURBOC__  || \    defined  __BORLAND__ || defined __LCC__     #define __CONIO_SOPORTADO__#endif#ifdef __CONIO_SOPORTADO__     #include <conio.h>     #define PAUSA() \          printf ("Presione una tecla para volver al men&#65533;..."); getch()     #define LEER_TECLA() getch()     #define LIMPIAR_PANTALLA() clrscr()#elif defined __MINGW32__     #define LEER_TECLA() getchar()     #define PAUSA() system("PAUSE")     #define LIMPIAR_PANTALLA() system("CLS")     #else          #define LEER_TECLA() getchar()          #define PAUSA() getchar()          #define LIMPIAR_PANTALLA()#endif#define TAM 5#define SALIR '12'int suma=0,m=0,g=0;float promedio=0;void menu(void);int leer_opcion(void);int generar_elementos (int arreglo[]);void mostrar (int arreglo[]);void burbuja (int arreglo[]);void seleccion (int arreglo[]);int menor (int arreglo[], int desde);void insercion (int arreglo[]);void quicksort (int arreglo[]);void ord_rap (int arreglo[], int inf, int sup);void copiar_arr (int *desde, int *hacia);int main(){     int arreglo[TAM];     int copia_arreglo[TAM];     char opcion = 0;     while (opcion != SALIR)          {          menu();          opcion = leer_opcion();          switch (opcion)               {               case '1':                    generar_elementos(arreglo);                    copiar_arr(arreglo, copia_arreglo);                    LIMPIAR_PANTALLA();                    printf ("\n\n\tSe generaron los siguientes elementos:\n");                    mostrar (arreglo);                    break;               case '2':                    LIMPIAR_PANTALLA();                    printf ("\n\n\tLos elementos del arreglo son:\n");                    mostrar (arreglo);                    break;               case '3':                    burbuja (arreglo);                    copiar_arr(copia_arreglo, arreglo);                    break;               case '4':                    seleccion (arreglo);                    copiar_arr(copia_arreglo, arreglo);                    break;               case '5':                    insercion (arreglo);                    copiar_arr(copia_arreglo, arreglo);                    break;               case '6':                    quicksort (arreglo);                    copiar_arr(copia_arreglo, arreglo);                    break;               case '7':                    LIMPIAR_PANTALLA();                    printf("Suma es=%d\n",suma);                    PAUSA();                    break;               case '8':                    LIMPIAR_PANTALLA();                    printf("Promedio es=%d\n",promedio);                    PAUSA();                    break;               case 'A':                    LIMPIAR_PANTALLA();                    printf ("Menor = %d\n",m);                    PAUSA ();                    break;               case 'B':                    LIMPIAR_PANTALLA();                    printf ("Mayor= %d\n",g);                    PAUSA ();                    break;               }          }     return 0;}void menu(void){     LIMPIAR_PANTALLA();     printf ("\n\n\t   Menu:\n");     printf ("\n\t1) Iniciar a introducir numeros.");     printf ("\n\t2) Mostrar los elementos.");     printf ("\n\t3) Ordenamiento burbuja.");     printf ("\n\t4) Ordenamiento por selecci&#65533;n.");     printf ("\n\t5) Ordenamiento por inserci&#65533;n.");     printf ("\n\t6) Ordenamiento rapido .");     printf ("\n\t7) Suma");     printf ("\n\t8) Promedio");     printf ("\n\tA) Menor.");     printf ("\n\tB) Menor.");     printf ("\n\t9) Salir.");     printf ("\n\n\t   Ingrese su opci&#65533;n por favor: ");}int leer_opcion(void){     char opcion;     opcion = LEER_TECLA();     while (opcion < '1' || opcion > SALIR)          {          opcion = LEER_TECLA();          }          return opcion;}int generar_elementos (int arreglo[]){     int i,x;     for (i=0; i<TAM; i++)     {     scanf ("%d",&arreglo[i]);          suma+=arreglo[i];          promedio=suma/TAM;          m=arreglo[0];          g=arreglo[9];          }     return TAM;}void mostrar (int arreglo[]){     int i,x;     for (i=0; i<TAM; i++)          printf ("\n\tElemento[%2d] = %d", i,arreglo[i] );     printf ("\n\n\t");     PAUSA();}void burbuja (int arreglo[]){     int i, j;     int temp;     for (i=1; i<TAM; i++)          for (j=0; j<TAM - i; j++)               if (arreglo[j] > arreglo[j+1])                    {                    /* Intercambiamos */                    temp = arreglo[j];                    arreglo[j] = arreglo[j+1];                    arreglo[j+1] = temp;                    }     LIMPIAR_PANTALLA();     printf ("\n\n\tOrdenamiento burbuja.");     printf ("\n\tEl arreglo ordenado es:\n");     mostrar (arreglo);}void seleccion (int arreglo[]){     int i;     int temp, pos_men;     for (i=0; i<TAM - 1; i++)          {          pos_men = menor(arreglo, i);          temp = arreglo[i];          arreglo[i] = arreglo [pos_men];          arreglo [pos_men] = temp;          }     LIMPIAR_PANTALLA();     printf ("\n\n\tOrdenamiento por selecci&#65533;n.");     printf ("\n\tEl arreglo ordenado es:\n");     mostrar (arreglo);}int menor (int arreglo[], int desde){     int i, menor;     menor = desde++;     for (i=desde; i<TAM; i++)          if (arreglo[i] < arreglo[menor])               menor = i;     return menor;}void insercion (int arreglo[]){     int i, j, temp;     for (i=1; i<TAM; i++)          {          temp = arreglo[i];          j = i - 1;          while ( (arreglo[j] > temp) && (j >= 0) )               {               arreglo[j+1] = arreglo[j];               j--;               }          arreglo[j+1] = temp;          }     LIMPIAR_PANTALLA();     printf ("\n\n\tOrdenamiento por inserci&#65533;n.");     printf ("\n\tEl arreglo ordenado es:\n");     mostrar (arreglo);}void quicksort (int arreglo[]){     ord_rap (arreglo, 0, TAM - 1);     LIMPIAR_PANTALLA();     printf ("\n\n\tOrdenamiento r&#65533;pido (QUICKSORT).");     printf ("\n\tEl arreglo ordenado es:\n");     mostrar (arreglo);}void ord_rap (int arreglo[], int inf, int sup){     int elem_div = arreglo[sup];     int temp ;     int i = inf - 1, j = sup;     int cont = 1;     if (inf >= sup)          return;     while (cont)          {          while (arreglo[++i] < elem_div);          while (arreglo[--j] > elem_div);          if (i < j)               {               temp = arreglo[i];               arreglo[i] = arreglo[j];               arreglo[j] = temp;               }          else              cont = 0;          }     temp = arreglo[i];     arreglo[i] = arreglo[sup];     arreglo[sup] = temp;     ord_rap (arreglo, inf, i - 1);     ord_rap (arreglo, i + 1, sup);}void copiar_arr (int *desde, int *hacia){     int i;     if ( (desde == NULL) || (hacia == NULL) )          return;     for (i=0; i<TAM; i++)         hacia[i] =desde[i];}