Created
December 20, 2013 13:36
-
-
Save mertyildiran/8054835 to your computer and use it in GitHub Desktop.
nxn'lik bir matrise Cramer uygulayan program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// nxn'lik bir matrise Cramer uygulayan program | |
// Mehmet Mert Yıldıran 12060367 | |
// Ubuntu terminal altında çalıştırma: | |
// gcc cramer.c -o cramer | |
// ./cramer | |
#include<stdio.h> | |
void readmatrix(int m[][8], int s){ | |
int i,j; | |
printf("Matrisin elemanlarını sırasıyla Enter'a basarak giriniz: \n"); | |
for(i=0;i<s;i++) | |
for(j=0;j<s;j++) | |
scanf("%d", &m[i][j]); | |
} | |
int determinant(int m[][8],int s){ | |
int i, j, k, det,cramermatrix[15][15], product, plussum = 0, minussum = 0; | |
if (s == 2) | |
det = m[0][0]*m[1][1] - m[0][1]*m[1][0]; | |
else | |
{ | |
for(i=0;i<s;i++) | |
for(j=0;j<s;j++) | |
cramermatrix[i][j] = m[i][j]; | |
for(i=0;i<s;i++) | |
for(j=s;j<(2*s-1);j++) | |
cramermatrix[i][j] = m[i][j-s]; | |
for(i=0;i<s;i++){ | |
product = 1; | |
for(j = 0; j <s; j++) | |
product = product*cramermatrix[j][i+j]; | |
plussum += product; | |
} | |
for(i=s-1;i<(2*s-1);i++){ | |
product = 1; | |
for(j = 0; j <s; j++) | |
product = product*cramermatrix[j][i-j]; | |
minussum += product; | |
} | |
det = plussum - minussum; | |
} | |
return det; | |
} | |
int main(){ | |
int matrix[8][8], det, size; | |
printf("Matrisin boyutunu giriniz (n*n) örn. 4 : "); | |
scanf("%d", &size); | |
readmatrix(matrix, size); | |
det = determinant(matrix, size); | |
printf("\n Cramer kuralına göre matrisin determinantı: \n det = %d\n\n", det); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment