Ejemplo 1: invertir una matriz en cpp
#include<iostream>
using namespace std;
int main()
int n=3;
int arr[]=1,2,3,4;while(n>=0)
cout<<arr[n];
n--;return0;
Ejemplo 2: invertir una matriz en c ++
#include <iostream>
using namespace std;
int main()// While loopconst int SIZE=9;
int arr [SIZE];
cout <<"Enter numbers: n";for(int i =0; i <SIZE; i++)
cin >> arr[i];for(int i =0; i <SIZE; i++)
cout << arr[i]<<"t";
cout << endl;
cout <<"Reversed Array:n";
int temp, start =0, end =SIZE-1;while(start < end)
temp = arr[start];
arr[start]= arr[end];
arr[end]= temp;
start++;
end--;for(int i =0; i <SIZE; i++)
cout << arr[i]<<"t";
cout << endl;return0;
Ejemplo 3: invertir una matriz en c ++
#include <iostream>
using namespace std;
int main()const int SIZE=9;
int arr [SIZE];
cout <<"Enter numbers: n";for(int i =0; i <SIZE; i++)
cin >> arr[i];for(int i =0; i <SIZE; i++)
cout << arr[i]<<"t";
cout << endl;
cout <<"Reversed Array:n";
int end =SIZE-1, temp;for(int i =0; i < end; i++)
temp = arr[i];
arr[i]= arr[end];
arr[end]= temp;
end--;/* Reverse using while loop
int temp, start = 0, end = SIZE-1;
while (start < end)
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
*/for(int i =0; i <SIZE; i++)
cout << arr[i]<<"t";
cout << endl;
Ejemplo 4: matriz inversa de c ++
int arr[5]=1,2,3,4,5;//Initialize arrayfor(int i =0; i <size(arr); i++)//Create temporary variable to hold current value in array
int temp = arr[i];//Set the current value in the array to the mirrored value in array
arr[i]= arr[size(arr)-1- i];//Set mirrored value in array to temp, swapping the two numbers
arr[size(arr)-1- i]= temp;
Ejemplo 5: matriz de cadena inversa java
import java.util.Arrays;publicclassReverseStringArrayInJavapublicstaticvoidmain(String[] args)String[] strHierarchy =newString[]"Junior Developer","Senior Developer","Team Lead","Project Manager","Senior Manager","CEO";System.out.println("Given string array: "+Arrays.toString(strHierarchy));for(int a =0; a < strHierarchy.length/2; a++)String strTemp = strHierarchy[a];
strHierarchy[a]= strHierarchy[strHierarchy.length- a -1];
strHierarchy[strHierarchy.length- a -1]= strTemp;System.out.println("Reversed string array: ");for(int a =0; a < strHierarchy.length; a++)System.out.println(strHierarchy[a]);
Ejemplo 6: reverse () en c ++
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
using namespace std;
int main()
vector<int>a =11,22,33,44,99,55;reverse(a.begin(), a.end());
auto it = a.begin();for(it= a.begin(); it!=a.end(); it++)
cout <<*it <<' ';
Nos puedes respaldar nuestro estudio poniendo un comentario y puntuándolo te damos las gracias.
¡Haz clic para puntuar esta entrada!
(Votos: 1 Promedio: 2)