miércoles, 28 de mayo de 2014

Practica 6

Problema 1
- Código

- Ejecución

- Pseudocódigo 
Inicio

A[7][11],x,y: int

posicion(y,x)
LeerDatos(A)
maximos(A)

Fin

Funcion posicion(posy: int, posx: int)
{
for(posy=2 to 7 step posy++)
 {
 write "  ", (posy-1)
 }
 for(posx=1 to 11 step pos++)
 {
 write "  ", (posx+30)
 }
}

Funcion LeerDatos(A[7][11]: int)
{
 w,q: int
 for(w=2 to 7 step w++)
 {
  for(q=1 to 11 step q++)
  {
  read A[q][w]
  }
 }
}

Funcion maximos(A[7][11]: int)
 s,z: int
 maximo1=0: int
 maximo2=0: int
 maximo3=0: int
 for(s=2 to 7 step s++)
 { 
  for(z=1 to 11 step z++)
  {
  if(A[z][s]>=maximo1 && A[z][s]<maximo2)
  then
   {
   maximo1=A[z][s]
   }
  else if(A[z][s]>=maximo2 && A[z][s]<maximo3)
   then
   {
   maximo2=A[z][s]
   }
  else if(A[z][s]>=maximo3 && A[z][s]>0)
  then 
  {
   maximo3=A[z][s]
   }
  }
 }
 write "el primer maximo es  :", maximo1
 write "el segundo maximo es :", maximo2
 write "el tercer maximo es  :", maximo3
}
   
Problema 2
- Código

- Ejecución

- Pseudocódigo 
Inicio

A[3,5], X[5], Y[3]: int

dar_valores_arreglo_2d_3x5(A)

dar_valores_arreglo_1d_5(X)

formula(A, X, Y)

desplegar_valores(A, X, Y)

Fin

funcion dar_valores_arreglo_2d_3x5(a[3,5]:int)
{
r, c:int

for(r=0 to 2 step r=r+1)
for(c=0 to 4 step c=c+1)
{
write " Determine el valor de A[", r ,"][", c ,"]: "
read a[r,c]
}
}

funcion dar_valores_arreglo_1d_5(x[5]:int)
{
c:int

for(c=0 to 4 c=c+1)
{
write " Determine el valor de X[", c ,"]: "
read x[c]
}
}

funcion formula(a[3,5]:int, x[5]:int, y[3]:int)
{
r, c:int
for(r=0 to 2 step r=r+1)
{
y[r]=0
for(c=0 to 4 step c=c+1)
y[r]=y[r]+a[r,c]*x[c]
}
}

funcion desplegar_valores(a[3,5]:int, x[5]:int, y[3]:int)
{
r, c:int
for(r=0 to 2 step r=r+1)
{
write " Y[", r ,"] = "
for(c=0 to 4 step c=c+1)
{
if(c!=4)
then
write "(", a[r,c] ," x ", x[c] ,") + "
else
write "(", a[r,c] ," x ", x[c] ,") = "
}
Problema 3
- Código

- Ejecución

- Pseudocódigo 
Inicio
matriz[20][20], promedio, sumat, dmayor, dmenor:real
columnas, filas:int


introducir(matriz, filas, columnas, sumat, promedio, dmayor, dmenor)
desplegar(matriz, filas, columnas)
fila(matriz, filas, columnas)
columna(matriz, filas, columnas)

write "El dato mayor es: ", dmayor
write "El dato menor es: ", dmenor
write "La suma total es: ", sumat
write "El promedio es : ", promedio

Fin

funcion desplegar(matriz[20][20]:real, filas:int, columnas:int)
{
r, c:int
write "---------------------------TABLA---------------------------"

for(r=0 to r<filas step r++)
{
for(c=0 to c<columnas step c++)
{
write "| ", matriz[r][c], " |"
}}
}


funcion introducir(matriz[20][20]:real, filas:int, columnas:int, sumat:real, promedio:real, dmayor:real, dmenor:real, dmenor:real)
{
sumat=0
dmayor=0
dmenor
a, b, i, j:int


write "Introduzca el numero de filas :"
read filas
write "Introduzca el numero de columnas: "
read columnas


for(i=0 to i<filas step i++)
{
for(j=0 to j<columnas step j++)
{
write "Introduczca el dato [", (i+1), ",", (j+1), "]: "
read matriz[i][j]

if(matriz[i][j]>dmayor)
then
dmayor=matriz[i][j]

sumat+=matriz[i][j]
dmenor=sumat
}
}

for(a=0 to a<renglones step a++)
{
for(b=0 to b<columnas step b++)
{
if(matriz[a][b]<dmenor)
dmenor=matriz[a][b]
}
}
promedio=(real)sumat/(renglones*columnas)
}

funcion fila(matriz[20][20]:real, filas:int, columnas:int)
{
suma[20]: real
mayor, menor: real 
m=0, b=0, i, j, k, x: int


for(i=0 to i<filas step i++)
{
suma[i]=0
for(j=0 to j<columnas step j++)
{
suma[i]+=matriz[i][j]
}
write "La Suma de la fila ", (i+1), " es: ", suma[i]
}
mayor=suma[0]

for(x=1 to x<filas step x++)
{
if(suma[x]<mayor)
then
{
menor=suma[x]
b=x
}}
write " La fila de menor valor es la numero: ", (b+1)

for(k=1 to k<renglones step k++)
{
if(suma[k]>mayor)
{
mayor=suma[k]
m=k
}
}
write "La fila de mayor vaalor es la numero ", (m+1)
}



funcion columna(matriz[20][20]:real, filas:int, columnas:int)
{
suma[20]:real
mayor, menor:real
m=0, b=0, k, x: int


for(i=0 to i<columnas step i++)
{
suma[i]=0
for(j=0 to j<filas step j++)
{
entrada>>matriz[i][j]
suma[i]+=matriz[j][i]
}
write "La suma de la columna ", (i+1), " es: ", suma[i]
}
mayor=suma[0]

for(x=1 to x<columnas step x++)
{
if(suma[x]<mayor)
then
{
menor=suma[x]
b=x
}}
write " La columna de menor valor es la numero: ", (b+1)

for(k=1 to k<columnas step k++)
{
if(suma[k]>mayor)
{
mayor=suma[k]
m=k
}}
write "La columna de mayor valor es la numero: ", (m+1)
}

Problema 4
- Código

- Ejecución

- Pseudocódigo 
Inicio

nombre[15][16]: char
calificacion[15][4]: int
promedio[15]: float

write "PROGRAMACION ESTRUCTURADA"
ingresardatos(nombre,calificacion)
promedio_alum(calificacion,promedio)
despliegue(calificacion,nombre,promedio)
promedio_gral(promedio)
write "Alumnos con promedio mas alto: "
promedio_max(nombre,promedio)

Fin


Funcion ingresardatos(nombre[15][16]:char, calificacion[15][4]: int)
{
 i,j: int
 for(i=o to 15 step i++)
  {
   write "Nombre del alumno", (i+1), ":"
   read nombre[i],16
    for(j=0 to 4 step j++)
     {
      do
{
write "Ingresar Calificacion", (j+1), ":"
read calificacion[i][j]
  if(calificacion[i][j]>100 or calificacion[i][j]<0)
   {
    write "Calificacion no valida"
    }
}
while(calificacion[i][j]>100 or calificacion[i][j]<0)
      }
   }
}


Funcion promedio_alum(calif[15][4]: int, promedio[15]: float)
{
 f,c,suma: int
 for(f=0 to 15 step f++)
  {
   suma=0
   for(c=0 to 4 step c++)
    {
     suma = suma + calif[f][c]
     }
     promedio[f] = suma/4
   }
}


Funcion despliegue(calificaciones[15][4]: int, nombre[15][16]: char, promedio[15]: float)
{
 i.j: int
 write "Nombre    Examen 1    Examen 2    Examen 3   Examen 4   Promedio"
 for(i=0 to 15 step i++)
  {
   write "  ",nombre[i]
   for(j=0 to 4 step j++)
    {
     write " ",calificacion[i][j]
    }
   write "  ", promedio[i]
  }
}


Funcion promedio_gral(promAlm[15]: int)
{
 i: int
 suma,PromGrl: float
 suma = 0
 for(i=0 to 14 step i++)
  {
   suma = suma + promAlm[i]
   }
 PromGrl = suma/15
 write "El promedio general del grupo es: ", PromGrl
}


Funcion promedio_max(nombres[15][16]: char, prom[15]: float)
{
 i,j,k,max: int
 for(i=0 to 3 step i++)
  { 
   max = 0
   for(j=0 to 15 step j++)
   {
    if(prom[j]>max)
     {
      max=prom[j]
      k=j
     }
    }
  Write "  ",nombres[k],"  ",prom[k]
  prom[k] = 0
 }
}


No hay comentarios:

Publicar un comentario