Created
December 20, 2013 13:12
-
-
Save mertyildiran/8054581 to your computer and use it in GitHub Desktop.
// nxn'lik bir matrise Gauss Elimination 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 Gauss Elimination uygulayan program | |
// Mehmet Mert Yıldıran 12060367 | |
// Ubuntu terminal altında çalıştırma: | |
// gcc gauss.c -o gauss | |
// ./gauss | |
#include<stdio.h> | |
#define MAX 10 | |
int lcm(int x,int y); | |
int main() | |
{ | |
int i,j,k,r,c,a[MAX][MAX],b[MAX][MAX],det=1,l,d1,d2; | |
printf("\nMatrisin satır sayısını giriniz: "); | |
scanf("%d",&r); | |
printf("\nMatrisin sütun sayısını giriniz: "); | |
scanf("%d",&c); | |
if(r==c) | |
{ | |
printf("\nMatrisin elemanlarını sırasıyla Enter'a basarak giriniz:\n"); | |
for(i=0;i<r;i++) | |
{ | |
for(j=0;j<c;j++) | |
{ | |
scanf("%d",&a[i][j]); | |
} | |
} | |
for(i=0;i<r-1;i++) | |
{ | |
for(j=i+1;j<r;j++) | |
{ | |
l=lcm(a[i][i],a[j][i]); | |
if(l!=0&&(a[i][i]!=0&&a[j][i]!=0)) | |
{ | |
l=(a[i][i]*a[j][i])/l; | |
d1=l/a[i][i]; | |
d2=l/a[j][i]; | |
a[j][i]=0; | |
for(k=i+1;k<r;k++) | |
{ | |
a[j][k]=(d2*a[j][k])-(d1*a[i][k]); | |
} | |
} | |
} | |
} | |
printf("\nGauss Eliminasyonu sonrası oluşan matris:\n"); | |
for(i=0;i<r;i++) | |
{ | |
for(j=0;j<c;j++) | |
{ | |
printf("%d\t",a[i][j]); | |
} | |
printf("\n"); | |
} | |
} | |
else | |
{ | |
printf("\nEliminasyon yapılamadı! Matrisin satır ve sütun sayıları eşit olmalı.\n"); | |
} | |
return 0; | |
} | |
int lcm(int x,int y) | |
{ | |
int t; | |
while (y != 0) | |
{ | |
t=y; | |
y=x%y; | |
x=t; | |
} | |
return x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment