Beruflich Dokumente
Kultur Dokumente
a[4]='d';
BaseAddres=100
100+4*1
e.g.
float a[10];
a[4]=2.5f;
BaseAddres=100
100+4*4
e.g.
struct student{
int id; // 4
char name[30];
float cgpa;
}
student a[10];
a[4].cgpa=2.5f;
BaseAddres=100
100+4*38
a 2x3
10 20 30
40 50 60
int a[2][3];
a[0][0]=10;
a[1][2]=60;
10 20 30 40 50 60
ii) Col Major (fortran, cobol)
10 40 20 50 30 60
Mapping Function
1) Row Major
Ba+ i*n+j *sizeofType
i=row index
j=col index
n= size of total cols in matrix
2) Col Major
Ba+ j*n+i *sizeofType
i=row index
j=col index
n= size of total rows in matrix
10 20 30
40 50 60
int a[2][3];
a[0][0]=10;//100
a[1][2]=60;//120
a[1][1]=50;//116
10 20 30
40 50 60
int a[2][3];
a[0][0]=10;//100
a[1][0]=40;//104
a[1][2]=60;// 120
..............................................
Example Print Array
void main(){
int a[2][3]={{10,20,30},
{40,50,60}};
print(a,2,3);
int b[2][4]={{10,20,30,40},
{40,50,60,70}};
print(b,2,4);// not workable
...................................
void main(){
int a[2][3]={{10,20,30},
{40,50,60}};
print(a,2,3);
int b[2][4]={{10,20,30,40},
{40,50,60,70}};
print(b,2,4);// not workable
}
......................................
void main(){
int *a=new int [6];
a[0]=10;a[1]=20;a[2]=30;a[3]=40;a[4]=50;a[5]=60;
print(a,2,3);
..........................................
void main(){
int *a=new int [6];
a[0]=10;a[1]=20;a[2]=30;a[3]=40;a[4]=50;a[5]=60;
print(a,2,3);
...............................................
#include <iostream>
#include <string>
return temp;
}
private :
int *p;
int row;
int col;
};
void main(){
Matrix a(2,3);
a.get();
Matrix b(3,2);
b.get();
Matrix c(2,2);
c=a.multiply(b);
c.print();
}
....................................................
#include <iostream.h>
class Matrix{
public :
Matrix() { }
Matrix (int r,int c){
row=r;
col=c;
p=new int[row*col];
for(int i=0;i<row*col;i++)
p[i]=0;
}
void get() {
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
cin>>p[i*col+j];
}
void print() {
for(int i=0;i<row;i++){
for(int j=0;j<col;j++)
cout<<p[i*col+j]<<"\t";
cout<<endl;
}
}
Matrix mul(Matrix b){
Matrix temp(row,b.col);
for(int i=0;i<row;i++)
for(int j=0;j<b.col;j++)
for(int k=0;k<col;k++)
temp.p[i*b.col+j]=
temp.p[i*b.col+j]+p[i*col+k]*
b.p[k*b.col+j];
return temp;
}
private:
int *p;
int row;
int col;
};
void main(){
Matrix a(2,3);
Matrix b(3,2);
Matrix c(2,2);
a.get();
a.print();
b.get();
b.print();
c=a.mul(b);
c.print();
}
..................................................
Assignment 1
1- Mutiply
2- Add
3- Transpose
4- Determinent
5- print
6- get
7- subtraction