Está en la página 1de 7

//////////////

#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <iomanip>
using namespace std;
//prototipo de funciones
int** gen(int f, int c);
void mostrar(int** arreglo, int f, int c);
int** comp(int** arr1, int** arr2, int f, int c);
//programa principal
int main() {
int f, c, ** arr1;
srand(time(NULL));
cout << "ingrese el numero de filas..:\t"; cin >> f;
cout << "ingrese el numero de columanas...:\t"; cin >> c;
arr1 = gen(f, c);
mostrar(arr1, f, c);
cout << "ahora le sumamos otra matriz...:\n";
int** arr2 = gen(f, c);
mostrar(arr2, f, c);
cout << "la suma de ambas matrices es...:\n";
int** arr3 = comp(arr1, arr2, f, c);
mostrar(arr3, f, c);
system("pause");
return 0;
}
int** gen(int f, int c) {
int** aux = new int* [f];
for (int i = 0; i < f; i++) {
aux[i] = new int[c];
for (int j = 0; j < c; j++) {
aux[i][j] = rand() % 10;
}
}
return aux;
}
void mostrar(int** arreglo, int f, int c) {
for (int i = 0; i < f; i++) {
for (int j = 0; j < c; j++) {
cout << setw(3) << arreglo[i][j] << " ";
}
cout << endl;
}
}
int** comp(int** arr1, int** arr2, int f, int c) {
int** aux2 = new int* [f];
for (int i = 0; i < f; i++) {
aux2[i] = new int[c];
for (int j = 0; j < c; j++) {
if (arr1[i][j] == arr2[i][j]) {
aux2[i][j] = arr1[i][j];
}
else {
aux2[i][j] = 0;
}
}
}
return aux2;
}
///////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
//PROBLEMA 1
/*#include <iostream>
using namespace std;
//prototipo de funciones
void intercambiar(int* numero1, int* numero2);
//programa principal
int main() {
int num1, num2;
cout << "ingrese numero 1...:\t"; cin >> num1;
cout << endl;
cout << "ingrese numero 2...:\t"; cin >> num2;
cout << "valores antes del intercambio...:\t" << num1 << " " << num2 << endl;
intercambiar(&num1, &num2);
cout << "valores depues del intermcambio.:\t" << num1 << " " << num2 << endl;
system("pause");
return 0;
}
void intercambiar(int* numero1, int* numero2) {
int temp = *numero1;
*numero1 = *numero2;
*numero2 = temp;
}*/

//PROBLEMA 2
/*
#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <iomanip>
using namespace std;
void suma(int** arreglo, int f, int c);
int main() {
int f, c, sum;
srand(time(NULL));
cout << "///INGRESE EL TAMAÑO DEL VECTOR///...\n";
cout << "ingrese el numero de filas...:\t"; cin >> f;
cout << endl;
cout << "ingrese el numero de columnas..:\t"; cin >> c;
int** arreglo1 = new int* [f];
for (int i = 0; i < c; i++) {
arreglo1[i] = new int[c];
}
suma(arreglo1, f, c);
system("pause");
return 0;
}
void suma(int** arreglo, const int f,const int c) {
int **p = new int*[f];
int sumatoria = 0;
for (int i = 0; i < f; i++) {
for (int j = 0; j < c; j++) {
arreglo[i][j] = rand() % 19 - 9;
}
}
cout << endl << endl;
cout << "la matriz es ....:\n";
for (int i = 0; i < f; i++) {
for (int j = 0; j < c; j++) {
cout << setw(3) << arreglo[i][j] << " ";
}
cout << endl;
}
for (p = arreglo; p < arreglo + f; p++) {
for (int k = 0; k < c; k++) {
sumatoria += (*p)[k];
}
}
cout << "la sumatoria de los elementos de la matriz es ....:\t" << sumatoria
<< endl;
}
*/
//PROBLEMA 3
/*
#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <iomanip>
using namespace std;
void ordenar(int** arreglo, int f, int c);
int main() {
int f, c, sum;
srand(time(NULL));
cout << "///INGRESE EL TAMAÑO DEL VECTOR///...\n";
cout << "ingrese el numero de filas...:\t"; cin >> f;
cout << endl;
cout << "ingrese el numero de columnas..:\t"; cin >> c;
int** arreglo1 = new int* [f];
for (int i = 0; i < c; i++) {
arreglo1[i] = new int[c];
}
ordenar(arreglo1, f, c);
system("pause");
return 0;
}
void ordenar(int** arreglo, const int f, const int c) {
int** p = new int* [f];
int sumatoria = 0;
for (int i = 0; i < f; i++) {
for (int j = 0; j < c; j++) {
arreglo[i][j] = rand() % 19 - 9;
}
}
cout << endl << endl;
cout << "la matriz es ....:\n";
for (int i = 0; i < f; i++) {
for (int j = 0; j < c; j++) {
cout << setw(3) << arreglo[i][j] << " ";
}
cout << endl;
}
cout << endl;
cout << "la matriz arreglada es...:\n";
for (p = arreglo; p < arreglo + f; p++) {
for (int k = 1; k < c; k++) {
if ((*p)[k] < (*p)[k-1]) {
int aux = (*p)[k];
(*p)[k] = (*p)[k - 1];
(*p)[k - 1] = aux;
}
}
}
for (p = arreglo; p < arreglo + f; p++) {
for (int k = 0; k < c; k++) {
cout << setw(3) << (*p)[k] << " ";
}
cout << endl;
}
}*/

//PROBLEMA 4
/*
#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <iomanip>
using namespace std;
void ordenar(int** arreglo, int f, int c);
int main() {
int f, c, sum;
srand(time(NULL));
cout << "///INGRESE EL TAMAÑO DEL VECTOR///...\n";
cout << "ingrese el numero de filas...:\t"; cin >> f;
cout << endl;
cout << "ingrese el numero de columnas..:\t"; cin >> c;
int** arreglo1 = new int* [f];
for (int i = 0; i < c; i++) {
arreglo1[i] = new int[c];
}
ordenar(arreglo1, f, c);
system("pause");
return 0;
}
void ordenar(int** arreglo, const int f, const int c) {
int** p = new int* [f];
int sumatoria = 0; int co, lu;
bool ver = false;
for (int i = 0; i < f; i++) {
for (int j = 0; j < c; j++) {
arreglo[i][j] = rand() % 19 +1;
}
}
cout << endl << endl;
cout << "la matriz es ....:\n";
for(int i = 0; i < f; i++) {
for (int j = 0; j < c; j++) {
cout << setw(3) << arreglo[i][j] << " ";
}
cout << endl;
}
cout << endl;
/*for (p = arreglo; p < arreglo + f; p++) {
for (int k = 0; k < c; k++) {
cout << setw(3) << (*p)[k] << " ";
}
cout << endl;
}*/
/*
int num;
cout << "ingrese el numero que quieras buscar...:\t"; cin >> num;
bool encontrado = false;
for (int i = 0; i < f; i++) {
for (int j = 0; j < c; j++) {
if (arreglo[i][j] == num) {
encontrado = true;
cout << "El elemento " << num << " se encuentra en la
posición " << i+1 << "x" << j+1 << endl;
break;
}
}
if (encontrado) {
break;
}
}
if (!encontrado) {
cout << "No se encontró el elemento " << num << " en la matriz." << "-
1 " << endl;
}

}*/
/*
#include <iostream>
#include <string>
using namespace std;
int main() {
std::cout << "Ingrese texto...:\n";
char texto[10]; int c = 0;
cin.getline(texto, 100, '\n');
char* ptr = new char[10];
for (*ptr=texto[10]; ptr < ptr+10; ptr++) {
switch (*ptr)
{
case 'a': c++; break;
case 'e': c++; break;
case 'i': c++; break;
case 'o': c++; break;
case 'u': c++; break;
}
}
cout << "hay " << c << " vocales" << endl;

system("pause");
return 0;
}
*/
/*
#include <iostream>
#include <string>
using namespace std;
int main() {
string texto;
cout << "ingrese texto...:\t"; cin >> texto;
for (int i=texto.length(); i>=0 ; i--) {
cout << texto[i];
}
system("pause");
return 0;
}
*/
/*
#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <iomanip>
using namespace std;
//prototipo de funciones
int** gen(int f, int c);
void mostrar(int** arreglo, int f, int c);
int** sum(int** arr1, int** arr2, int f, int c);
//programa principal
int main() {
int f, c, **arr1;
srand(time(NULL));
cout << "ingrese el numero de filas..:\t"; cin >> f;
cout << "ingrese el numero de columanas...:\t"; cin >> c;
arr1 = gen(f, c);
mostrar(arr1, f, c);
cout << "ahora le sumamos otra matriz...:\n";
int** arr2 = gen(f, c);
mostrar(arr2, f, c);
cout << "la suma de ambas matrices es...:\n";
int** arr3 = sum(arr1, arr2, f, c);
mostrar(arr3, f, c);
system("pause");
return 0;
}
int** gen(int f, int c) {
int** aux = new int* [f];
for (int i = 0; i < f; i++) {
aux[i] = new int[c];
for (int j = 0; j < c; j++) {
aux[i][j] = rand() % 199 - 99;
}
}
return aux;
}
void mostrar(int** arreglo, int f, int c) {
for (int i = 0; i < f; i++) {
for (int j = 0; j < c; j++) {
cout << setw(3) << arreglo[i][j] << " ";
}
cout << endl;
}
}
int** sum(int** arr1, int** arr2, int f, int c) {
int** aux2 = new int* [f];
for (int i = 0; i < f; i++) {
aux2[i] = new int[c];
for (int j = 0; j < c; j++) {
aux2[i][j] = arr1[i][j] + arr2[i][j];
}
}
return aux2;
}*/
#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <iomanip>
using namespace std;
//prototipo de funciones
int** gen(int f, int c);
void mostrar(int** arreglo, int f, int c);
int** comp(int** arr1, int** arr2, int f, int c);
//programa principal
int main() {
int f, c, ** arr1;
srand(time(NULL));
cout << "ingrese el numero de filas..:\t"; cin >> f;
cout << "ingrese el numero de columanas...:\t"; cin >> c;
arr1 = gen(f, c);
mostrar(arr1, f, c);
cout << "ahora le sumamos otra matriz...:\n";
int** arr2 = gen(f, c);
mostrar(arr2, f, c);
cout << "la suma de ambas matrices es...:\n";
int** arr3 = comp(arr1, arr2, f, c);
mostrar(arr3, f, c);
system("pause");
return 0;
}
int** gen(int f, int c) {
int** aux = new int* [f];
for (int i = 0; i < f; i++) {
aux[i] = new int[c];
for (int j = 0; j < c; j++) {
aux[i][j] = rand() % 199 - 99;
}
}
return aux;
}
void mostrar(int** arreglo, int f, int c) {
for (int i = 0; i < f; i++) {
for (int j = 0; j < c; j++) {
cout << setw(3) << arreglo[i][j] << " ";
}
cout << endl;
}
}
int** comp(int** arr1, int** arr2, int f, int c) {
int** aux2 = new int* [f];
for (int i = 0; i < f; i++) {
aux2[i] = new int[c];
for (int j = 0; j < c; j++) {
aux2[i][j] = arr1[i][j] + arr2[i][j];
}
}
return aux2;
}

También podría gustarte