Creating a Matrix Multiplication With C++
# include <iostream>
# include <conio.h>
# include <stdio.h>
# define Nmaks 10
typedef int matrix [Nmaks] [Nmaks];
void main ()
{
int h, n, i, j;
matrices A, B, C;
court <<"Multiplication A 2x2 and B 2x2 \ n \ n";
n = 3;
court <<"Enter the entries of the matrix A \ n";
for (i = 1; i <= n; i)
{
for (j = 1; j <= n; j)
{
court <<"A [" <<i <<","<< j <<"] ="; cin>> A [i] [j];
}
}
court <<"\ n";
court <<"Enter the entries of the matrix B \ n";
for (i = 1; i <= n; i)
{
for (j = 1; j <= n; j)
{
court <<"B [" <<i <<","<< j <<"] ="; cin>> B [i] [j];
}
}
clrscr;
court <<"\ n";
/ / Process the sum matrix C = A B
for (i = 1; i <= n; i)
{
for (j = 1; j <= n; j)
{
{C [i] [j] = (A [i] [1] * B [i] [j]) (A [i] [2] * B [2] [j]) (A [i] [3 ] * B [3] [j]);}
}
}
for (h = 1; h <20; h)
{
gotoxy (35, h 1);
court <<"| |";
}
gotoxy (35.1);
court <<"__________________________________________";
gotoxy (35.20);
court <<"|________________________________________";
gotoxy (38.3);
court <<("Answer:");
/ / process matrix C
gotoxy (38.4);
court <<"C = A B ';
gotoxy (38.5);
court <<"Hsl =";
for (i = 1; i <= n; i)
{
for (j = 1; j <= n; j)
{
gotoxy (40 5 * j, 3 2 * i);
court <<A [i] [j];
}
}
gotoxy (58.3 2);
court <<"";
for (i = 1; i <= n; i)
{
for (j = 1; j <= n; j)
{
gotoxy (58 5 * j, 3 2 * i);
court <<B [i] [j];
}
}
gotoxy (41.12);
court <<"=";
for (i = 1; i <= n; i)
{
for (j = 1; j <= n; j)
{
gotoxy (39 6 * j, 3 3 * i 6);
court <<C [i] [j];
}
}
getch ();
}
# include <conio.h>
# include <stdio.h>
# define Nmaks 10
typedef int matrix [Nmaks] [Nmaks];
void main ()
{
int h, n, i, j;
matrices A, B, C;
court <<"Multiplication A 2x2 and B 2x2 \ n \ n";
n = 3;
court <<"Enter the entries of the matrix A \ n";
for (i = 1; i <= n; i)
{
for (j = 1; j <= n; j)
{
court <<"A [" <<i <<","<< j <<"] ="; cin>> A [i] [j];
}
}
court <<"\ n";
court <<"Enter the entries of the matrix B \ n";
for (i = 1; i <= n; i)
{
for (j = 1; j <= n; j)
{
court <<"B [" <<i <<","<< j <<"] ="; cin>> B [i] [j];
}
}
clrscr;
court <<"\ n";
/ / Process the sum matrix C = A B
for (i = 1; i <= n; i)
{
for (j = 1; j <= n; j)
{
{C [i] [j] = (A [i] [1] * B [i] [j]) (A [i] [2] * B [2] [j]) (A [i] [3 ] * B [3] [j]);}
}
}
for (h = 1; h <20; h)
{
gotoxy (35, h 1);
court <<"| |";
}
gotoxy (35.1);
court <<"__________________________________________";
gotoxy (35.20);
court <<"|________________________________________";
gotoxy (38.3);
court <<("Answer:");
/ / process matrix C
gotoxy (38.4);
court <<"C = A B ';
gotoxy (38.5);
court <<"Hsl =";
for (i = 1; i <= n; i)
{
for (j = 1; j <= n; j)
{
gotoxy (40 5 * j, 3 2 * i);
court <<A [i] [j];
}
}
gotoxy (58.3 2);
court <<"";
for (i = 1; i <= n; i)
{
for (j = 1; j <= n; j)
{
gotoxy (58 5 * j, 3 2 * i);
court <<B [i] [j];
}
}
gotoxy (41.12);
court <<"=";
for (i = 1; i <= n; i)
{
for (j = 1; j <= n; j)
{
gotoxy (39 6 * j, 3 3 * i 6);
court <<C [i] [j];
}
}
getch ();
}
0 comments:
Post a Comment