Dev - C++ - Problema de bucles

 
Vista:

Problema de bucles

Publicado por Carlos (9 intervenciones) el 20/10/2017 11:29:17
Buenos dias!! Tengo un pequeño problema con unos bucles. La idea era conseguir que el vector xq tuviera los valores de x1 x2 x3 en orden, sin dejar huecos, pero no lo consigo, supongo que es un problema de las condiciones iniciales y finales

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
#include <iostream>
 
using namespace std;
 
int main()
{
int nmax=101;
int a=3;
 
double x1[nmax],x2[nmax],x3[nmax],xq[3*nmax];
 
for(int i=0;i<nmax;i++){
 
    x1[i]=1;
    x2[i]=2;
    x3[i]=3;
}
 
 
for(int i=0,j=0;i<nmax+1||j<nmax+1;i++,j++){        //SAVE LOOP 1
        xq[i]=x1[j];
}
for(int i=nmax,j=0;i<(nLF*nmax)||j<nmax+1;i++,j++){   //SAVE LOOP 2
        xq[i]=x2[j];
}
for(int i=2*nmax,j=0;i<(nLF*nmax)+1||j<nmax+1;i++,j++){   //SAVE LOOP 3
        xq[i]=x3[j];
}
 
for(int i=0;i<nmax;i++){     //PRINT LOOP 1
 
    cout<<" i "<<i<<" "<<xq[i]<<endl;
}
cout<<"--------------------------------------------------------"<<endl;
 
for(int i=nmax;i<nLF*nmax;i++){//PRINT LOOP 2
 
    cout<<" i "<<i<<" "<<xq[i]<<endl;
}
cout<<"--------------------------------------------------------"<<endl;
 
for(int i=2*nmax-1;i<nLF*nmax;i++){//PRINT LOOP 3
 
    cout<<" i "<<i<<" "<<xq[i]<<endl;
}
    return 0;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder