Advertisement
Abelsor

VPL_S6_E2

Apr 12th, 2023
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. /*Función que copia los elementos del vector A en el vector B
  5. (manteniendo el orden original)*/
  6. void copiarVector(int A[], int B[], int N){
  7.     for(int i=0 ; i<N ; i++){
  8.         B[i] = A[i];
  9.     }
  10. }
  11.  
  12. /*Función que copia los elementos del vector A en el vector B
  13. (colocando los elementos en B en orden inverso que en A)*/
  14. void copiarVector_Inv(int A[], int B[], int N){
  15.     for(int i=0 ; i<N ; i++){
  16.         B[i] = A[N-1-i];
  17.     }
  18. }
  19.  
  20. /*Función auxiliar - Impresión de un vector*/
  21. void imprimirVector(int X[], int n){
  22.     int i;
  23.     for(i=0;i<n;i++) cout<<X[i]<<" "; cout<<endl;
  24. }
  25.  
  26. /*Función auxiliar - Lectura de un vector*/
  27. void leerVector(int X[], int n){
  28.     int i;
  29.     for(i=0;i<n;i++) cin>>X[i];
  30. }
  31.  
  32. int main(){
  33.      /*---NO MODIFICAR El MAIN*/
  34.     int opcion,n;
  35.     cin>>opcion;
  36.     cin>>n;
  37.     int a[n],b[n];
  38.     if(opcion==1){
  39.         leerVector(a,n);
  40.         copiarVector(a,b,n);
  41.         imprimirVector(b,n);
  42.     }
  43.     if(opcion==2){
  44.         leerVector(a,n);
  45.         copiarVector_Inv(a,b,n);
  46.         imprimirVector(b,n);
  47.     }
  48.     return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement