*
* Matrisler
*
*/
#include
#include
#include
typedef struct _MATRIX{
int **a;
int m,n;
}matris;
matris * allocatemem(int x,int y){
int i;
matris * m;
m = (matris *)malloc(sizeof(matris));
m->a = (int **)malloc(sizeof(int*) * x);
for(i=0;i
}
m->m = x;
m->n = y;
return m;
}
void freeallocatedmemory(matris * m){
int i;
for(i=0;i
free(*((m->a)+i));
}
free(m->a);
free(m);
}
matris * topla(matris * bir , matris * iki){
matris * a;
int x,y;
int i,j;
if((bir->m != iki->m) || (bir->n != iki->n)){
printf("verilen matrsiler toplanamaz.!!!");
return NULL;
}
x = bir->m;
y = bir->n;
a = allocatemem(x,y);
for(i=0;i
}
}
return a;
}
matris * cikar(matris * bir , matris * iki){
matris * a;
int x,y;
int i,j;
if((bir->m != iki->m) || (bir->n != iki->n)){
printf("verilen matrsiler cikarilmaz.!!!");
return NULL;
}
x = bir->m;
y = bir->n;
a = allocatemem(x,y);
for(i=0;i
}
}
return a;
}
matris * carp(matris * bir,matris * iki){
int i,j,k;
matris *sonuc;
if(bir->m != iki->n){
printf("verilen matrsiler carpılmaz.!!!");
return NULL;
}
sonuc = allocatemem(bir->m,iki->n);
for(i=0;i
for(j=0;j
*(*(sonuc->a + i)+j) = 0;
for(k=0;k
*(*(sonuc->a + i)+j) += (*(*(bir->a + j)+k)) * (*(*(iki->a + k)+j));
}
}
}
return sonuc;
}
matris * transpoze(matris * a){
matris * tmp;
int i,j;
tmp = allocatemem(a->n,a->m);
for(i=0;i
for(j=0;j
*(*(tmp->a + i)+j) = *(*(a->a + j)+i);
}
}
freeallocatedmemory(a);
return tmp;
}
void yazdir(matris * a){
int i,j;
if(a==NULL) return;
printf("\n\n");
for(i=0;i
printf("[");
for(j=0;j
printf(" %d ",*(*(a->a + i)+j));
}
printf("]\n");
}
}
void sifirla(matris * a){
int i,j;
for(i=0;i
for(j=0;j
*(*(a->a + i)+j) = 0;
}
}
}
matris * matrisolustur(){
int m,n;
int i,j;
matris * a;
printf("Matrisi boyutlarını girin : ");
scanf("%d %d",&m,&n);
printf("\n\n a[%d][%d]",m,n);
a = allocatemem(m,n);
for(i=0;i
for(j=0;j
printf("\nA[%d][%d]",i+1,j+1);
scanf("%d",(*(a->a + i)+j));
}
}
return a;
}
char menu(){
char ch;
matris *a,*b,*c;
do{
printf("\n\n###############################################");
printf("\n# Matris islemleri ############################");
printf("\n###############################################");
printf("\n 1) Birinci Matrisi olustur");
printf("\n 2) İkinci Matrisi olustur");
printf("\n 3) Matrisleri Topla");
printf("\n 4) Matrsileri cikar");
printf("\n 5) Matrsileri carp");
printf("\n 6) Birinci matrisin transpozesini al");
printf("\n 7) Sonuc matrisini yazdır");
printf("\n 8) Programdan cikis");
printf("\n\n Seciminiz : ");
ch = getch();
switch(ch){
case('1'):
a = matrisolustur();
break;
case('2'):
b = matrisolustur();
break;
case('3'):
c = topla(a,b);
break;
case('4'):
c = cikar(a,b);
break;
case('5'):
c = carp(a,b);
break;
case('6'):
c = transpoze(a);
break;
case('7'):
yazdir(c);
break;
case('8'):
exit(0);
break;
}
}while(1);
}
int main(){
menu();
}