0% found this document useful (0 votes)
36 views10 pages

Ejercicio I:: Int Main Int Matriz

The document contains 6 code exercises involving 2D arrays (matrices) in C++. Exercise 1 defines a 5x3 matrix and creates a second matrix by squaring the values of the first matrix based on their column index being odd or even. Exercise 2 calculates the average of each row of a 6x4 input matrix and counts values greater than a given minimum. Exercise 3 performs calculations on the sum of diagonals, border rows/columns, and other regions of a 4x4 input matrix. Exercise 4 defines and prints a 5x6 matrix, appends it with copies of itself, and calculates a determinant. Exercise 6 checks if an input n×n matrix is "magic" by verifying if all row sums,

Uploaded by

Yuse LH
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)
36 views10 pages

Ejercicio I:: Int Main Int Matriz

The document contains 6 code exercises involving 2D arrays (matrices) in C++. Exercise 1 defines a 5x3 matrix and creates a second matrix by squaring the values of the first matrix based on their column index being odd or even. Exercise 2 calculates the average of each row of a 6x4 input matrix and counts values greater than a given minimum. Exercise 3 performs calculations on the sum of diagonals, border rows/columns, and other regions of a 4x4 input matrix. Exercise 4 defines and prints a 5x6 matrix, appends it with copies of itself, and calculates a determinant. Exercise 6 checks if an input n×n matrix is "magic" by verifying if all row sums,

Uploaded by

Yuse LH
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/ 10

EJERCICIO I:

#include<iostream>
#include<windows.h>

int main(){
int matriz[100][100],matriz2[100][100],FILAS=5,COLUMNAS=3;

//Rellenando la matriz
for(int i=1;i<=+FILAS;i++){
for(int j=1;j<=COLUMNAS;j++)
{
cout<<"Digite un numero ["<<i<<"] ["<<j<<"]:"<<" ";
cin>>matriz[i] [j];

}
}

//Mostrando en pantalla la nueva matriz


for(int i=1;i<=FILAS;i++){
for(int j=1;j<=COLUMNAS;j++)
{
cout<<matriz[i] [j]<<" ";

}
cout<<"\n" ;
}

for(int i=1;i<=FILAS;i++){
for(int j=1;j<=COLUMNAS;j++)
{
if(j%2!=0)
matriz2[i] [j]=matriz[i] [j]*matriz[i] [j];
else
matriz2[i] [j]=matriz[i] [j]*matriz[i]
[j]*matriz[i] [j];
}
cout<<"\n" ;
}

for(int i=1;i<=FILAS;i++){
for(int j=1;j<=COLUMNAS;j++)
{
cout<<matriz2[i] [j]<<" ";

}
cout<<"\n" ;
}

return 0;
}
EJERCICIO III
#include<iostream>
#include<windows.h>

using namespace std;

int main(){
int matriz[100][100],matriz2[100][100],FILAS=6,COLUMNAS=4;

//Rellenando la matriz
for(int i=1;i<=+FILAS;i++){
for(int j=1;j<=COLUMNAS;j++){
cout<<"Digite un numero ["<<i<<"] ["<<j<<"]:"<<" ";
cin>>matriz[i] [j];

}
}

//Mostrando en pantalla la nueva matriz


for(int i=1;i<=FILAS;i++){
for(int j=1;j<=COLUMNAS;j++){
cout<<matriz[i] [j]<<" ";

}
cout<<"\n" ;
}

double prom[10]={0,0,0,0,0,0};
for(int i=1;i<=FILAS;i++){
for(int j=1;j<=COLUMNAS;j++){
prom[i]=prom[i]+matriz[i] [j];
}
prom[i]=prom[i]/4;
cout<<"El promedio de la viga "<<i <<" es: "<<prom[i]<<"\n" ;
}

//pasaron la prueba

int valmin,cant=0;
cout<<"ingrese el valor minimo: ";
cin>>valmin;
for(int i=1;i<=FILAS;i++){
for(int j=1;j<=COLUMNAS;j++){
if(matriz[i][j]>=valmin)
cant++;
}
}
cout<<"La cantidad de fuerzas que pasaron la prueba es: "<<cant
<<"\n" ;

return 0;
}
EJERCICIO IV
#include<iostream>
#include<windows.h>

using namespace std;

int main(){
int matriz[100][100],FILAS=4,COLUMNAS=4;

//Rellenando la matriz
for(int i=1;i<=+FILAS;i++){
for(int j=1;j<=COLUMNAS;j++){
cout<<" Digite un numero ["<<i<<"] ["<<j<<"]:"<<" ";
cin>>matriz[i] [j];

}
}

//Mostrando en pantalla la nueva matriz


for(int i=1;i<=FILAS;i++){
for(int j=1;j<=COLUMNAS;j++){
cout<<matriz[i] [j]<<" ";

}
cout<<"\n" ;
}
int sumaf=0;
int sumac=0;
int sumad=0;
int sumas=0;
for(int i=1;i<=FILAS;i++)
{
for(int j=1;j<=COLUMNAS;j++)
{

if (i==j)
sumad=sumad+matriz[i][j];

}
cout<<"\n" ;
}
for(int i=1;i<=FILAS;i++)
{
for(int j=1;j<=COLUMNAS;j++)
{

if (i + j == 5)
sumas=sumas+matriz[i][j];

}
cout<<"\n" ;
}
for(int i=1;i<=FILAS;i++)
{
for(int j=1;j<=COLUMNAS;j++)
{
if(i==1 || i==4)
sumaf=sumaf+matriz[i] [j];
if(j==1 || j==4)
sumac=sumac+matriz[i] [j];
}
cout<<"\n" ;
}
cout<<" la suma de la diagonal principal es: "<<sumad<<endl;
cout<<" la suma de la diagonal secundaria es: "<<sumas<<endl;
cout<<" la suma de f1+f4 es: "<<sumaf<<endl;
cout<<" la suma de c1+c4 es: "<<sumac;

return 0;
}

EJERCICIO V
#include<iostream>
#include<conio.h>

using namespace std;

int main(){
int matriz[20][20]={{10,3,5,4,4,5},
{1,2,3,4,7,8,},{4,5,6,5,1,8,},{7,8,9,5,8,3},{1,5,8,9,6,8},{4,5,6,5,1,10,}},
FILAS=5, COLUMNAS=5;
//Rellenando la matriz
/*for(int i=1;i<=FILAS;i++){
for(int j=1;j<=COLUMNAS;j++){
if(matriz[i][j]>0){

}
cout<<"Digite un numero ["<<i<<"] ["<<j<<"]:"<<" ";
cin>>matriz[i] [j];
if(matriz[i][j]<0){
cout<<"ingrese numero positivo"<<endl;
cout<<"Digite un numero ["<<i<<"] ["<<j<<"]:"<<" ";
cin>>matriz[i] [j];
}

}
}
*/

//Mostrando en pantalla la matriz


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

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

for(int j=0;j<=COLUMNAS;j++){

if(i>5 ){
matriz[i] [j]=matriz[i-6] [j];}
cout<<matriz[i] [j]<<"\t";

}
cout<<"\n";
}

int
multi1[100]={1,1,1,1,1,1},multi2[100]={1,1,1,1,1,1},mult2=1,suma1=0,suma2=0;
for(int i=0;i<=FILAS;i++){
int t1=i,t2=10-i;
for(int j=0;j<=COLUMNAS;j++){
multi1[i]=multi1[i]*matriz[t1] [j];
multi2[i]=multi2[i]*matriz[t2] [j];
//cout<<"multipliccion "<<multi1[i]<<"\t";
t1++;
t2=t2-1;
}
cout<<"\n";
suma1=suma1+multi1[i];

suma2=suma2+multi2[i];
//cout<<endl<<"sunaaaaa "<<suma1<<"\t"<<endl;
}
//cout<<endl<<"suma= "<<suma1<<"\t"<<suma2<<endl;
cout<<endl<<"determinante= "<<suma2-suma1;
getch();
return 0;

}
EJERCICIO VI
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int **matriz, n, *sumaFila, *sumaColu, sumaDiag = 0;
bool esMagica = true;
cout<<"Ingrese el tamanio de la matriz: ";
cin>>n;

matriz = new int*[n];


for(int i = 0; i < n; i++)
matriz[i] = new int[n];
sumaFila = new int[n];
sumaColu = new int[n];
for(int i = 0; i < n; i++)
sumaColu[i] = 0;

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


{
sumaFila[i] = 0;
for(int j = 0; j < n; j++)
{
cout<<"matriz["<< i <<"]["<< j <<"]: ";
cin>>matriz[i][j];
sumaFila[i] += matriz[i][j];
sumaColu[j] += matriz[i][j];
if(i == j)
sumaDiag += matriz[i][j];
}
}

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


{
for(int j = 0; j < n; j++)
cout<<setw(3)<<matriz[i][j];
cout<<endl;
}

for(int i = 1; i < n; i++)


if(sumaFila[i - 1] != sumaFila[i] ||
sumaColu[i - 1] != sumaColu[i] ||
sumaDiag != sumaFila[i])
esMagica = false;

if(esMagica)
cout<<"\nLa matriz es Magica\n";
else
cout<<"\nLa matriz no es Magica\n";

system("pause");
return 0;
}

You might also like