Sunday, 23 October 2011

C++ Matriks Addition Program

C++ Matrix Addition Program. The matrix is the development of systems of linear persamann. The matrix can be used to formulate a variety of problems including the problems of business and economics. The matrix is a collection of numbers that are presented regularly in rows and columns that form a square or rectangular and contained between a pair of parentheses.

Two matrices can only be added if the same number of columns and rows. The sum matrix Amxm with Bmxm Cmxm is a new matrix whose elements are the sum of these two matrix elements.

With changing times, the matrix can now also been created for the program. One implementation of the current matrix is often used in IT Programming course is a sum of matrices in C + + programming.

The following syntax will I give an example of matrix addition program C + +. It is the task given Mr. Oka told us children of international class. Than after the program is rarely used paid more, more I share to all friends. Here it is its syntax.


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

#define Nmaks 25

typedef int matriks[Nmaks][Nmaks];
void main()
{
 int colA,colB,rowA,rowB,i,j;
 matriks A,B,C;
 char answer;

 do
 {
 do
 {
  clrscr();
  cout<<"MATRIKS A : "<<endl;
  cout<<"Masukkan Jumlah Baris Matriks A : ";
  cin>>rowA;
  cout<<"Masukkan Jumlah Kolom Matriks A : ";
  cin>>colA;
  cout<<endl<<endl;
  cout<<"MATRIKS B : "<<endl;
  cout<<"Masukkan Jumlah Baris Matriks B : ";
  cin>>rowB;
  cout<<"Masukkan Jumlah Kolom Matriks B : ";
  cin>>colB;
 }
 while ((colA!=colB) || (rowA!=rowB));

 clrscr();
 cout<<"Masukkan Nilai Matriks A : "<<endl;
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colA;j++)
  {
   cout<<"A["<<i<<","<<j<<"] = ";
   cin>>A[i][j];
  }
 }

 clrscr();
 cout<<"Masukkan Nilai Matriks B : "<<endl;
 for(i=1;i<=rowB;i++)
 {
  for(j=1;j<=colB;j++)
  {
   cout<<"B["<<i<<","<<j<<"] = ";
   cin>>B[i][j];
  }
 }

 clrscr();
 cout<<endl;
 //Proses Penjumlahan Matriks
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colA;j++)
  {
   C[i][j] = A[i][j] + B[i][j];
  }
 }

 clrscr();
 //Output Matriks A
 gotoxy(1,5);
 cout<<"A = ";
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colA;j++)
  {
   gotoxy(2+4*j,2+2*i);
   cout<<A[i][j];
  }
 }

 //Output Matriks B
 gotoxy(1,13);
 cout<<"B = ";
 for(i=1;i<=rowB;i++)
 {
  for(j=1;j<=colB;j++)
  {
   gotoxy(2+4*j,10+2*i);
   cout<<B[i][j];
  }
 }

 //Output Matriks C
 gotoxy(1,20);
 cout<<"C = ";
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colA;j++)
  {
   gotoxy(3+4*j,17+2*i);
   cout<<A[i][j];
  }
 }

 gotoxy(17,20);
 cout<<" + ";
 for(i=1;i<=rowB;i++)
 {
  for(j=1;j<=colB;j++)
  {
   gotoxy(18+4*j,17+2*i);
   cout<<B[i][j];
  }
 }

 gotoxy(32,20);
 cout<<" = ";
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colA;j++)
  {
   gotoxy(33+4*j,17+2*i);
   cout<<C[i][j];
  }
 }

 getch();
 clrscr();
 cout<<"== PROGRAM SELESAI =="<<endl<<endl;
 cout<<"Mau Melakukan Perhitungan Lagi?? [Y/T]"; cin>>answer;
 }
 while ((answer == 'y') || (answer == 'Y'));
}



Thanks

No comments:

Post a Comment