Advertisement
sapitando

Ordenador de números em C(Array) - Versão simplificada.

Jul 30th, 2016
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4.  
  5. int main(){
  6.     const int MaxSizeList = 10;
  7.     double Nro[MaxSizeList], NroAux1, NroAux2;
  8.     unsigned int PosArray, PosLastSmaller, CounterPos, TotalPos, LastPos, FirstPos;
  9.  
  10.     clrscr;
  11.  
  12.     Nro[0] = 8.45;
  13.     Nro[1] = 1;
  14.     Nro[2] = 4;
  15.     Nro[3] = 2;
  16.     Nro[4] = 15;
  17.     Nro[5] = 6;
  18.     Nro[6] = 7;
  19.     Nro[7] = 3;
  20.     Nro[8] = 8;
  21.     Nro[9] = 5;
  22.  
  23.     TotalPos = (MaxSizeList - 1);
  24.     FirstPos = 0;
  25.     LastPos = 9;
  26.  
  27.     for(PosArray = FirstPos; PosArray < LastPos; PosArray++ ){
  28.         NroAux1 = Nro[PosArray];
  29.         PosLastSmaller = PosArray;
  30.         for(CounterPos = (PosArray + 1); CounterPos <= LastPos; CounterPos++ ){
  31.             if(NroAux1 >= Nro[CounterPos]){
  32.                 PosLastSmaller = CounterPos;
  33.                 NroAux1 = Nro[PosLastSmaller];
  34.             }
  35.         }
  36.         if(PosLastSmaller > PosArray){
  37.             for(CounterPos = PosArray; CounterPos <= LastPos; CounterPos++){
  38.                 if((CounterPos >= PosLastSmaller) && (CounterPos < LastPos)){
  39.                     NroAux2 = Nro[CounterPos + 1];
  40.                     }
  41.                 else{
  42.                     NroAux2 = Nro[CounterPos];
  43.                     }
  44.                 Nro[CounterPos] = NroAux1;
  45.                 NroAux1 = NroAux2;
  46.             }
  47.         }
  48.     }
  49.  
  50.     for(CounterPos = FirstPos; CounterPos <= TotalPos; CounterPos++){
  51.         printf("%3d : %3.2f\n",CounterPos, Nro[CounterPos]);
  52.  
  53.     }
  54.     getch();
  55.  
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement