-->
.

sábado, 5 de mayo de 2012

Arreglos (Ejercicio 19-20)


Programa 19:
Ingreso de una matriz bidimensional, se realice la suma de sus columnas y los resultados, asignarlos a una matriz unidimensional.
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5.  clrscr();
  6.  int md[3][3];
  7.  int t[3]={0,0,0};
  8.  int i,j,x=3,y=3;
  9.  for(i=0;i<3;i++)
  10.   {
  11.    for(j=0;j<3;j++)
  12.     {
  13.      gotoxy(x,y);scanf("%d",&md[i][j]);
  14.      x=x+3;
  15.      t[j]=t[j]+md[i][j];
  16.     }
  17.     x=3;
  18.     y=y+3;
  19.   }
  20.   y=12;
  21.   x=3;
  22.   for(j=0;j<3;j++)
  23.    {
  24.     gotoxy(x,y-1);printf("=");
  25.     gotoxy(x,y);printf("%d\n",t[j]);
  26.     x=x+3;
  27.    }
  28.   getch();
  29. }

Programa 20:
Multiplicación de dos matrices cuadradas de 3x3.

  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. void main()
  5. {
  6.  clrscr();
  7.  int m1[3][3],m2[3][3],c[3][3];
  8.  int i,j,x=3,y=3,k;
  9.  for(i=0;i<3;i++)
  10.   {
  11.    for(j=0;j<3;j++)
  12.     {
  13.      gotoxy(x,y);scanf("%d",&m1[i][j]);
  14.      x=x+3;
  15.     }
  16.     x=3;
  17.     y=y+3;
  18.   }
  19.    x=15;
  20.    y=3;
  21.   for(i=0;i<3;i++)
  22.    {
  23.    for(j=0;j<3;j++)
  24.     {
  25.      gotoxy(x,y);scanf("%d",&m2[i][j]);
  26.      x=x+3;
  27.     }
  28.     x=15;
  29.     y=y+3;
  30.   }
  31.    x=30;
  32.    y=3;
  33.    for(k=0;k<3;k++)
  34.    {
  35.    for(i=0;i<3;i++)
  36.    { c[k][i]=0;
  37.    for(j=0;j<3;j++)
  38.     {
  39.      c[k][i]=c[k][i]+m1[k][j]*m2[j][i];
  40.     }
  41.    gotoxy(x,y);printf("%d",c[k][i]);
  42.     x=x+5;
  43.    }
  44.   x=30;
  45.   y=y+3;
  46.   }
  47.   getch();
  48. }

0 comentarios:

Publicar un comentario

Popular Posts

Followers