0% found this document useful (0 votes)
22 views7 pages

Segundo Talle4r

The document contains 7 code snippets that demonstrate different uses of arrays and matrices in C++. The first code snippet takes user input to populate a vector and then sorts the vector in ascending and descending order. The second snippet calculates the highest and lowest temperatures from a 7 day temperature array. The third populates and prints a 5x5 matrix. The remaining code snippets demonstrate operations on 2D arrays/matrices like addition, multiplication, checking for symmetry, calculating combinations and factorials, and searching for specific values.

Uploaded by

anahi posada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

Segundo Talle4r

The document contains 7 code snippets that demonstrate different uses of arrays and matrices in C++. The first code snippet takes user input to populate a vector and then sorts the vector in ascending and descending order. The second snippet calculates the highest and lowest temperatures from a 7 day temperature array. The third populates and prints a 5x5 matrix. The remaining code snippets demonstrate operations on 2D arrays/matrices like addition, multiplication, checking for symmetry, calculating combinations and factorials, and searching for specific values.

Uploaded by

anahi posada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

PRIMER PUNTO

#include <iostream>
using namespace std;

int main()
{
int des = 0, asc = 0, n = 0;
int vector[999]{};

cout << "Ingrese la cantidad la cantidad de numeros del vector" << endl;
cin >> n;

for (int i = 0; i < n; i++) {


cout << "Digite un numero:" << endl;
cin >> vector[i];
}

for (int i = 0; i < n; i++) {


cout << "En la posicion " << i << " --> " << vector[i] << endl;
}
for (int i = 0; i < n - 1; ++i) {
for (int j = 0; j < n - 1; ++j) {
if (vector[j] > vector[j + 1]) {
asc = vector[j];
vector[j] = vector[j + 1];

vector[j + 1] = asc;
}

}
}
for (int i = 0; i < n; ++i) {

cout << "Los numeros del vector de manera ascendente:" << vector[i] << endl;

}
for (int i = 0; i < n - 1; ++i) {
for (int j = 0; j < n - 1; ++j) {
if (vector[j] < vector[j + 1]) {
des = vector[j];

vector[j] = vector[j + 1];

vector[j + 1] = des;
}
}
}
for (int i = 0; i < n; i++) {

cout << "Los numeros del vector de manera descendente:" << vector[i] << endl;

}
}

2. SEGUNDO PUNTO
#include <iostream>

using namespace std;

int main() {
float temperatura[7];
float mayor = 0, menor;
int i;

for (i = 0; i < 7; i++) {


cout << "Temperatura captada del dia " << i + 1 << ": ";
cin >> temperatura[i];
}

//temperatura mayor
for (i = 0; i < 7; i++)
if (temperatura[i] > mayor)
mayor = temperatura[i];

//temperatura minima
menor = temperatura[0];
for (i = 1; i < 7; i++)
if (temperatura[i] < mayor)
menor = temperatura[i];

cout << "La temperatura mas alta fue de: " << mayor << endl;
cout << "La temperatura mas baja fue de: " << menor << endl;

}
3. TERCER PUNTO
#include <iostream>
using namespace std;

int main() {

float matriz[5][5]{};

for (int i = 0; i < 5; i++) {


for (int j = 0; j < 5; j++) {
cout << "Digite un numero para la posicion[" << i << "]["<<j<< "]" << endl;
cin >> matriz[i][j];
}

}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
cout << matriz[i][j];
}
cout << "\n";
}

}
4. CUARTO PUNTO

#include <iostream>
using namespace std;

int main()
{
int mat1[3][6] = { {1,10,11,8,14,-15},{2,-3,0,0,5,-12},{3,2,7,12,0,-1} };
int mat2[3][6] = { {11,25,35,89,-12,-2},{-9,-5,14,0,3,-3},{-8,0,-5,-9,0,-5} };
int matsuma[3][6]{};
int matresta[3][6]{};
int matproducto[3][6]{};
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 6; j++) {
matsuma[i][j] = mat1[i][j] + mat2[i][j];
matresta[i][j] = mat1[i][j] - mat2[i][j];
matproducto[i][j] = mat1[i][j] * mat2[i][j];

}
}
cout << "\nSuma de las dos matices";
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 6; j++) {

cout << "[" << matsuma[i][j] << "]";

}
cout << "\nResta de las dos matrices";
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 6; j++) {

cout << "[" << matresta[i][j] << "]";


}
}
cout << "\nProducto punto de las dos matrices";
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 6; j++) {

cout << "[" << matproducto[i][j] << "]";


}
}

}
5. QUINTO PUNTO
#include<iostream>
using namespace std;

int main() {

int numeros[999][999] = {};


int filas, columnas;
char band = 'F';

cout << "Ingrese el numero de filas: "; cin >> filas;


cout << "Ingrese el numero de columnas: "; cin >> columnas;

for (int i = 0; i < filas; i++) {


for (int j = 0; j < columnas; j++) {
cout << "Ingrese un numero [" << i << "][" << j << "]: ";
cin >> numeros[i][j];
}
}

if (filas == columnas) {
for (int i = 0; i < filas; i++) {
for (int j = 0; j < columnas; j++) {
if (numeros[i][j] == numeros[j][i]) {
band = 'V';
}
}
}
}

if (band == 'V') {
cout << "\nEs una matriz simetrica";
}
else {
cout << "\nNo es una matriz simetrica";
}

}
6. Sexto punto

#include<iostream>
using namespace std;

int factorial(int n)
{
if (n < 2)
return 1;
else
return n * factorial(n - 1);
}

int combinacion(int n, int r)


{
if (r == 1)
return n;
else
{
if (n == r)
return 1;
else
return factorial(n) / (factorial(r) * factorial(n - r));
}
}

int main()
{
for (int i = 0; i <= 6; i++)
{
for (int ii = 0; ii <= i; ii++)
cout << combinacion(i, ii) << " ";
cout << endl;
}

}
7. Séptimo punto
#include<iostream>
using namespace std;

int main() {

int matriz[9][6] = { {11,1,9,3,1,3,},


{3,25,14,2,4,16,},
{0,2,6,4,15,1},
{12,3,3,21,1,17},
{22,6,19,27,2,16},
{4,28,20,12,10,26},
{18,1,2,8,25,30},
{23,13,29,31,4,3},
{2,24,10,2,3,11} };
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 6; j++) {
matriz[i][j];
if (matriz[i][j] == 6) {
cout << "El numero 6 fue encontrado en la fila[" << i << "]" << "en la columna[" << j
<< "]" << endl;
}

if (matriz[i][j] == 10) {
cout << "El numero 10 fue encontrado en la fila[" << i << "]" << "en la columna[" << j
<< "]" << endl;
}

if (matriz[i][j] == 11) {
cout << "El numero 11 fue encontrado en la fila[" << i << "]" << "en la columna[" << j
<< "]" << endl;
}
}
}
}

You might also like