Invierte los valores contenidos en un vector
1 2 3 4 5 6 7 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 | {-Victor De la Rocha} {-Algoritmia@groups.msn.com} {-www.myalgorithm.com} uses crt;type vector=array [1..100] of integer; var arreglo:vector; cantidad,cont1,cont2,temp1,temp2,numero:integer;begin ClrScr; Write('Cantidad de valores: ');Readln(cantidad); writeln; for cont1:=1 to cantidad do begin Write('Valor ',cont1,': ');Readln(arreglo[cont1]); end; writeln; write('Valores originales: '); for cont1:=1 to cantidad do begin if cont1=cantidad then begin write(arreglo[cont1],'.'); end else begin write(arreglo[cont1],', '); end; end; writeln; write('Valor invertidos: '); for cont1:=1 to cantidad do begin if cont1=cantidad then begin arreglo[cont1]:=arreglo[cont1]*-1; write(arreglo[cont1],'.'); end else begin arreglo[cont1]:=arreglo[cont1]*-1; write(arreglo[cont1],', '); end; end; ReadKey; end. |
Cantidad: 28
Valor 1: -4
Valor 2: -37
Valor 3: -7
Valor 4: -50
Valor 5: 50
Valor 6: -13
Valor 7: -32
Valor 8: 42
Valor 9: 2
Valor 10: -10
Valor 11: 23
Valor 12: -3
Valor 13: 1
Valor 14: -19
Valor 15: -21
Valor 16: 1
Valor 17: 45
Valor 18: 20
Valor 19: 8
Valor 20: -12
Valor 21: -23
Valor 22: 16
Valor 23: 33
Valor 24: 44
Valor 25: -2
Valor 26: 27
Valor 27: 24
Valor 28: 2
Valores invertidos
Valor 1: 4
Valor 2: 37
Valor 3: 7
Valor 4: 50
Valor 5: -50
Valor 6: 13
Valor 7: 32
Valor 8: -42
Valor 9: -2
Valor 10: 10
Valor 11: -23
Valor 12: 3
Valor 13: -1
Valor 14: 19
Valor 15: 21
Valor 16: -1
Valor 17: -45
Valor 18: -20
Valor 19: -8
Valor 20: 12
Valor 21: 23
Valor 22: -16
Valor 23: -33
Valor 24: -44
Valor 25: 2
Valor 26: -27
Valor 27: -24
Valor 28: -2