Algoritmia - ayuda

 
Vista:

ayuda

Publicado por leidy (1 intervención) el 31/10/2006 23:01:36
hola como estas espero que bien, necesito los codigo los programas en lenguaje c++ de matrices primer ejercicio 1. (matriz triangular inferios) 2. matriz triangular inferior
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
Imágen de perfil de Alejandro

Programas en C++ para matrices triangulares inferior y superior

Publicado por Alejandro (307 intervenciones) el 07/03/2024 00:21:27
¡Hola Leidy! Claro, puedo proporcionarte los programas en C++ para trabajar con matrices triangulares inferior y superior. Aquí están los ejemplos:

1. Matriz triangular inferior en C++:

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
#include <iostream>
 
using namespace std;
 
const int MAX_FILAS = 3; // Puedes ajustar el tamaño según tus necesidades
 
void llenarMatrizTriangularInferior(int matriz[MAX_FILAS][MAX_FILAS]) {
    cout << "Ingrese los elementos de la matriz triangular inferior:" << endl;
    for (int i = 0; i < MAX_FILAS; i++) {
        for (int j = 0; j <= i; j++) {
            cin >> matriz[i][j];
        }
    }
}
 
void mostrarMatrizTriangularInferior(int matriz[MAX_FILAS][MAX_FILAS]) {
    cout << "Matriz triangular inferior:" << endl;
    for (int i = 0; i < MAX_FILAS; i++) {
        for (int j = 0; j < MAX_FILAS; j++) {
            if (j <= i) {
                cout << matriz[i][j] << " ";
            } else {
                cout << "0 ";
            }
        }
        cout << endl;
    }
}
 
int main() {
    int matrizTriangularInferior[MAX_FILAS][MAX_FILAS];
 
    llenarMatrizTriangularInferior(matrizTriangularInferior);
    mostrarMatrizTriangularInferior(matrizTriangularInferior);
 
    return 0;
}

2. Matriz triangular superior en C++:

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
#include <iostream>
 
using namespace std;
 
const int MAX_FILAS = 3; // Puedes ajustar el tamaño según tus necesidades
 
void llenarMatrizTriangularSuperior(int matriz[MAX_FILAS][MAX_FILAS]) {
    cout << "Ingrese los elementos de la matriz triangular superior:" << endl;
    for (int i = 0; i < MAX_FILAS; i++) {
        for (int j = i; j < MAX_FILAS; j++) {
            cin >> matriz[i][j];
        }
    }
}
 
void mostrarMatrizTriangularSuperior(int matriz[MAX_FILAS][MAX_FILAS]) {
    cout << "Matriz triangular superior:" << endl;
    for (int i = 0; i < MAX_FILAS; i++) {
        for (int j = 0; j < MAX_FILAS; j++) {
            if (j >= i) {
                cout << matriz[i][j] << " ";
            } else {
                cout << "0 ";
            }
        }
        cout << endl;
    }
}
 
int main() {
    int matrizTriangularSuperior[MAX_FILAS][MAX_FILAS];
 
    llenarMatrizTriangularSuperior(matrizTriangularSuperior);
    mostrarMatrizTriangularSuperior(matrizTriangularSuperior);
 
    return 0;
}

Estos programas permiten al usuario ingresar elementos para las matrices triangulares inferior y superior, respectivamente, y luego muestran la matriz resultante en pantalla. Puedes ajustar el tamaño de la matriz según tus necesidades. ¡Espero que te sean de utilidad!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar