lunes, 12 de noviembre de 2012

Practica 11


Problema 1
Pseudocodigo
tabla[5][5] int

r,c int
suma=0 int
for(r=0 to 5 step r ++)
{
for(c=0 to 5 step c ++)
{
Print "tabla[" , r , "," , c , "]=?"
read tabla[r][c]
}
}
for(r=0 to 5 step r ++)
{
suma=0
for(c=0 to 5 step c ++)
{
suma=suma+tabla[r][c]
Print tabla[r][c] , "\t"
}
Print suma
}


Codificación en C++
# include <iostream.h>
# include <conio.h>
# include <math.h>
int main ()
{
int tabla[5][5];
int r,c;
int suma=0;

for(r=0;r<5;r ++)
{
for(c=0;c<5;c ++)
{
cout<<"tabla["<<r<<","<<c<<"]=?";
cin>>tabla[r][c];
}
}
for(r=0;r<5; r ++)
{
suma=0;
for(c=0;c<5;c ++)
{
suma=suma+tabla[r][c];
cout<<tabla[r][c]<<"\t";
}
cout<<suma<<endl;
}
getch ();
return 0;
}






Problema 2
Pseudocodigo


matriz[5][6] int
i,j,mayor=0,pos int
suma=0 int
for(i=0 to 5 step i++)
{
for(j=0 to 5 step j ++)
{
Print "matriz[" , i , "," , j , "]=?"
Read matriz[i][j]
}
}
for(i=0 to 5 step i ++)
{
suma=0
for(j=0 to 5 step j ++)
{
suma=suma+matriz[i][j]
}
matriz[i][j]=suma
}
for(i=0 to 5 step i ++)
{
for(j=0 to 6 step j ++)
{
Print matriz[i][j] , "\t"
}
Print
}
for(i=0 to 5 step i ++)
{
if(matriz[i][5]>mayor)
{
mayor= matriz[i][5]
pos=i
}
}
Print "\n"
Print "el dato mayor es" , mayor
Print "el renglón en donde esta localizado en:" , pos


Codificación en C++
# include <iostream.h>
# include <conio.h>
# include <math.h>

int main ()
{
int matriz[5][6];
int i,j,mayor=0,pos;
int suma=0;
for(i=0;i<5;i ++)
{
for(j=0;j<5;j ++)
{
cout<<"matriz["<<i<<","<<j<<"]=?";
cin>>matriz[i][j];
}
}
for(i=0;i<5;i ++)
{
suma=0;
for(j=0;j<5;j ++)
{
suma=suma+matriz[i][j];
}
matriz[i][j]=suma;
}
for(i=0;i<5;i ++)
{
for(j=0;j<6;j ++)
{
cout<<matriz[i][j]<<"\t";
}
cout<<endl;
}
for(i=0;i<5;i ++)
{
if(matriz[i][5]>mayor)
{
mayor= matriz[i][5];
pos=i;
}
}
cout<<"\n"<<endl;
cout<<"el dato mayor es"<<mayor<<endl;
cout<<"el rneglon en donde esta localizado en:"<<pos<<endl;
getch ();
return 0;
}





Problema 3
Pseudocodigo


suma=0 int
m[4][5] int
r,c int
suma=0


for(c=0 to 5 step c++)
{
suma=0
for(r=0 to 4 step r++)
{
Print "m[" , r , c , "]:"
Read m[r][c]
suma=suma+m[r][c]
}
}
Print "La suma de columna" , c , "es:" , suma

Codificación en C++
#include <conio.h>
#include <iostream.h>
#include <math.h>
int main ()
{
int suma=0;
int m[4][5];
int r,c;
suma=0;
for(c=0;c<5;c++)
{
suma=0;
for(r=0;r<4;r++)
{
cout<<"m["<<r<<c<<"]:";
cin>>m[r][c];
suma=suma+m[r][c];
}
}
cout<<"La suma de columna"<<c<<"es:"<<suma<<endl;
getch ();
return 0;
}




Problema 4
Pseudocodigo


matriz[6][4], I, J, suma=0 int

for (I=0 to 5 step I++)
{
for (J=0 to 4 step J++)
{
Print "matriz[" , I , ", " , J , "] = "
Read matriz[I][J]
}
}
for (I=0 to 4 step I++)
{
suma=0
for (J=0 to 5 step J++)
{
suma=suma+matriz[J][I]
}
matriz[5][I]=suma
}
for (I=0 to 6 step I++)
{
for (J=0 to 4 step J++)
{
Print matriz[I][J] , "\t"
}
Print
}

Codificación en C++
#include <iostream.h>
#include <conio.h>
int main ()
{
int matriz[6][4], I, J, suma=0;
for (I=0; I<5; I++)
{
for (J=0; J<4; J++)
{
cout<<"matriz["<<I<<", "<<J<<"] = ";
cin>>matriz[I][J];
}
}
for (I=0; I<4; I++)
{
suma=0;
for (J=0; J<5; J++)
{
suma=suma+matriz[J][I];
}
matriz[5][I]=suma;
}
for (I=0; I<6; I++)
{
for (J=0; J<4; J++)
{
cout<<matriz[I][J]<<"\t";
}
cout<<endl;
}
getch ();
return 0;
}






Problema 5
Pseudocodigo


matriz[7][8], r, c, suma=0, mayor1=0, posc=0, mayor2=0, posr=0 int
randomize ()
Print "Matriz Original"
for (r=0 to 6 step r=r+1)
{
suma=0
for (c=0 to 7 step c=c+1)
{
matriz [r][c]=random (10)
suma=suma+matriz[r][c]
Print matriz[r][c] , "\t"
}
matriz[r][7]=suma
Print
}
for (c=0 to 7 step c=c+1)
{
suma=0
for (r=0 to 6 step r=r+1)
{
suma=suma+matriz[r][c]
}
matriz[6][c]=suma
}
matriz[6][7]=0
for (c=0 to 7 step c=c+1)
{
if (matriz[6][c]>mayor1)
{
mayor1=matriz[6][c]
posc=c
}
}
for (r=0 to 6 step r=r+1)
{
if (matriz[r][7]>mayor2)
{
mayor2=matriz[r][7]
posr=r
}
}
Print "\nMatriz con la suma de renglones y columnas"


for (r=0 to 7 step r=r+1)
{
for (c=0 to 8 step c=c+1)
{
Print matriz[r][c] , "\t"
}
Print
}
Print "\n"
Print "La suma mayor del renglon " , posr , " es = " , mayor2
Print "\n"
Print "La suma mayor de la columnas " , posc , " es = " , mayor1



Codificación en C++
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
int main ()
{
int matriz[7][8], r, c, suma=0, mayor1=0, posc=0, mayor2=0, posr=0;
randomize () ;
cout<<"Matriz Original"<<endl<<endl;
for (r=0; r<6; r=r+1)
{
suma=0;
for (c=0; c<7; c=c+1)
{
matriz [r][c]=random (10);
suma=suma+matriz[r][c];
cout<<matriz[r][c]<<"\t";
}
matriz[r][7]=suma;
cout<<endl;
}
for (c=0; c<7; c=c+1)
{
suma=0;
for (r=0; r<6; r=r+1)
{
suma=suma+matriz[r][c];
}
matriz[6][c]=suma;
}
matriz[6][7]=0;
for (c=0; c<7; c=c+1)
{
if (matriz[6][c]>mayor1)
{
mayor1=matriz[6][c];
posc=c;
}
}
for (r=0; r<6; r=r+1)
{
if (matriz[r][7]>mayor2)
{
mayor2=matriz[r][7];
posr=r;
}
}
cout<<"\nMatriz con la suma de renglones y columnas"<<endl<<endl;
for (r=0; r<7; r=r+1)
{
for (c=0; c<8; c=c+1)
{
cout<<matriz[r][c]<<"\t";
}
cout<<endl;
}
cout<<"\n";
cout<<"La suma mayor del renglon "<<posr<<" es = "<<mayor2<<endl;
cout<<"\n";
cout<<"La suma mayor de la columnas "<<posc<<" es = "<<mayor1<<endl;
getch ();
return 0;
}





Problema 6
Pseudocodigo


A[5][5], B[5][5] int
I,J int
random()
for(I=0 to 5 step I++)
{
for(J=0 to 5 step J++)
{
A[I][J]=random(1000)+1
B[J][I]=A[I][J]
}
}
Print "Matriz Original"
for(I=0 to 5 step I++)
{
for(J=0 to 5 step J++)
{
Print A[I][J] , "\t "
}
Print "\n"
}
Print "Matriz Transpuesta"
for(I=0 to 5 step I++)
{
for(J=0 to 5 step J++)
{
Print B[I][J] , "\t"
}
Print "\n"
}


Codificación en C++

#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
int main ()
{
int A[5][5], B[5][5];
int I,J;


randomize();
for(I=0;I<5;I++)
{
for(J=0;J<5;J++)
{
A[I][J]=random(1000)+1;
B[J][I]=A[I][J];
}
}
cout<<"Matriz Original"<<endl;
for(I=0;I<5;I++)
{
for(J=0;J<5;J++)
{
cout<< A[I][J]<<"\t "<<endl;
}
cout<<"\n"<<endl;
}
cout<<"Matriz Transpuesta"<<endl;
for(I=0;I<5;I++)
{
for(J=0;J<5;J++)
{
cout<<B[I][J]<<"\t"<<endl;
}
cout<<"\n"<<endl;
}
getch ();
return 0;
}






Problema 7
Pseudocodigo

A[5][5], B[5][5] int
I,J, suma=0 int
random()
for(I=0 to 5 step I++)
{
for(J=0 to 5 step J++)
{
A[I][J]=random(1000)+1
}
}
suma=0
for(I=0 to 5 step I++)
{
suma=suma+A[I][J]
}
Print "La Suma de la Diagonal Principal inversa es " , suma
suma=0
J=4
for(I=0 to 5 step I++)
{
suma=suma + A[I][J]
J=J-1
}
Print "La suma de la Diagonal Inversa es " , suma

Codificación en C++
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
int main ()
{
int A[5][5], B[5][5];
int I,J, suma=0;
randomize();
for(I=0;I<5;I++)
{
for(J=0;J<5;J++)
{
A[I][J]=random(1000)+1;
}
}
suma=0;
for(I=0;I<5;I++)
{
suma=suma+A[I][J];
}
cout<<"La Suma de la Diagonal Principal inversa es "<<suma<<endl;
suma=0;
J=4;
for(I=0;I<5;I++)
{
suma=suma + A[I][J];
J=J-1;
}
cout<<"La suma de la Diagonal Inversa es "<<suma<<endl;
getch ();
return 0;
}




No hay comentarios:

Publicar un comentario