#include<conio.h>
#include<iostream.h>
#define max 100
/*Nhap ma tran*/
void NhapMaTran(float A[max][max], int m, int n){
for(int i = 0; i<m; i++)
for(int j = 0; j<n; j++) {
cout<<"a["<<i<<"]["<<j<<"] = ";
cin>>A[i][j];
}
}
/*Xuat ma tran*/
void XuatMaTran(float A[max][max], int m, int n) {
for(int i=0 ; i<m; i++){
cout<<endl;
for(int j=0 ; j<n; j++)
cout<<A[i][j]<<"\t";
}
}
/*C = A+B*/
void CongMaTran(float A[max][max], float B[max][max], float C[max][max], int m, int n) {
for(int i = 0; i<m; i++)
for(int j = 0; j<n; j++)
C[i][j] = A[i][j]+B[i][j];
}
/*A cap mxn * B cap nxp = C cap mXp*/
void NhanMaTran(float A[max][max], float B[max][max], float C[max][max], int m, int n, int p){
for(int i = 0; i<m; i++)
for(int k = 0; k<p; k++) {
C[i][k]=0;
for(int j = 0; j<n; j++)
C[i][k] = C[i][k]+A[i][j]*B[j][k];
}
}
/*Chuong trinh chinh*/
void main(){
int m=3,n=2,p=3;
float A[max][max],B[max][max],C[max][max],D[max][max];
clrscr();
cout<<"Nhap ma tran A cap "<<m<<"x"<<n<<endl;
NhapMaTran(A,m,n);
cout<<"Nhap ma tran B cap "<<m<<"x"<<n<<endl;
NhapMaTran(B,m,n);
cout<<"Nhap ma tran C cap "<<n<<"x"<<p<<endl;
NhapMaTran(C,n,p);
cout<<"Ma tran A\n";
XuatMaTran(A,m,n);
cout<<"\nMa tran B\n";
XuatMaTran(B,m,n);
cout<<"\nMa tran C\n";
XuatMaTran(C,n,p);
cout<<"\nMa tran D = A+B\n";
CongMaTran(A,B,D,m,n);
XuatMaTran(D,m,n);
cout<<"\nMa tran D = A.C\n";
NhanMaTran(A,C,D,m,n,p);
XuatMaTran(D,n,p);
getch();
}
Tag: Ma trận, mảng 2 chiều, mảng hai chiều, phép cộng, phép nhân, C, C++
Related Post:
Code C#: Nhập, xuất với mảng 1 chiều (Console)using System;static void Main(string[] args){ int[] a = new int[10]; //nhap gia tri cho mang 1 chieu for (int i = 0; i < 10; i++){ Console.Write("Nhap a[{0}]=", i); a[i] = int.Parse(Console.ReadLine()); } //xuat mang 1 chieu for (int i… Read More
Code C#: Giải phương trình bậc 2 (Console)/* Giải và biện luận phương trình bậc 2 (sử dụng ứng dụng Console) */using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace GiaiPT_bac2{ class Program{ static void Main(string[] args){ float a, b, c; string xau;… Read More
Code C#: Code Examples sample source codesGet selected checkbox list itemsusing System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.CheckedListBox chkListPossibleValues; private System.Windows.Forms.ListBox lstSelected; priv… Read More
Code C#: Giải phương trình bậc nhất (Console)using System; namespace PhuongTrinhBacNhat{ class Program { static void Main(string[] args) { Console.Write("Nhap he so a :"); int a = int.Parse(Console.ReadLine()); Console.Write("Nhap h… Read More
Code C#: Code Examples sample source codesCenter form window using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class Form1 : System.Windows.Forms.Form { private Button myButton; public Form1() { this.AutoSc… Read More
Code C#: Tổng 2 số nguyên a, b nhập từ bàn phím (Console)using System;namespace Tong2so{ class Program { static void Main(string[] args) { int a, b, kq; Console.WriteLine(" Nhập gia tri a: "); a = int.Parse(Console.ReadLine()); … Read More
Klik untuk melihat kode: