Ejemplo 1: matriz inversa de c ++
int arr[5] = {1, 2, 3, 4, 5}; //Initialize array
for(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 2: imprimir una matriz al revés en c ++
#include <iostream>
// Print contents of an array in reverse order in C++
// using array indices
int main()
{
int arr[] = { 10, 20, 30, 40 };
size_t n = sizeof(arr)/sizeof(arr[0]);
// iterate backwards over the elements of an array
for (int i = n - 1; i >= 0; i--) {
std::cout << arr[i] << ' ';
}
return 0;
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)