
Error al mostrar vector en manera Descendente
Publicado por Jorge (1 intervención) el 13/10/2017 03:03:45
Hola! tengo un error el cual es, tiene bien la sintaxis pero el problema es que en forma ascendente muestra bien, pero en forma descendente lo muestra mal
me podrian ayudar??? Gracias! =) (DESARROLLADO EN Dev-cpp)
CODIGO:
me podrian ayudar??? Gracias! =) (DESARROLLADO EN Dev-cpp)
CODIGO:
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<windows.h>
#include<conio.h>
using namespace std;
void gotoxy(int x,int y){
HANDLE hcon;
hcon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD dwPos;
dwPos.X = x;
dwPos.Y= y;
SetConsoleCursorPosition(hcon,dwPos);
}
int vec[10],a; //llenar vector
int i,j,temp; //Ordenar el vector
int x,p; //MOSTRAR EL VECTOR
int opc,d; //VARIABLE DE LA OPCION
int v,sum,b; //MOSTRAR VECTOR YA ORDENADO
int y=5;
main (){
srand(time(NULL));
for(a=0;a<10;a++) //LLENANDO VECTOR 1
{
vec[a]=1+rand()%500;
cout<<vec[a]<<" ";
}
d=2;
for(x=0;x<11;x++){
gotoxy(8,8);cout<<vec[x]; //MOSTRAR VECTOR ORIGINAL
d=d+4;
}
for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
{
if(vec[j]<vec)
{
temp = vec[j]; //ORDENANDO VECTOR 1
vec[j] = vec;
vec = vec[j];
vec=temp;
}
}
}
gotoxy(3,8);cout<<"M E N U";
gotoxy(3,10);cout<<"ASCENDENTE (1)";
gotoxy(3,12);cout<<"DESCENDENTE (2)";
gotoxy(3,15);cout<<"Opcion = ";
gotoxy(12,15);cin>>opc;
if(opc==1){
sum=3;
for(v=0;v<10;v++){
gotoxy(sum,17);cout<<vec[v]<<" "; //Mostrar vector ya ordenado (ASCENDENTE)
sum=sum+4;
}
}
if(opc==2){
for(a=10;a>0;a--){
cout<<vec[a]<<" "; //MOSTRAR VECTOR DESCENDENTE
}
}
}
Valora esta pregunta


0