Last active
August 29, 2015 14:10
-
-
Save co3moz/6b48b80a4b9092d721dc to your computer and use it in GitHub Desktop.
Making a determinant with Chio Way..
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
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
class Matris { | |
private: | |
double* objects; | |
int k; | |
int iterator = 0; | |
public: | |
Matris(int k) { | |
objects = new double[k*k]; | |
this-> k = k; | |
} | |
~Matris() { | |
delete[] objects; | |
} | |
void set(double obj) { | |
objects[iterator++] = obj; | |
} | |
double determinant() { | |
if(this-> k == 2) return this-> objects[0] * this-> objects[3] - this-> objects[1]* this-> objects[2]; | |
Matris yeni(this-> k - 1); | |
for(int y = 0; y < this-> k - 1; y++) for(int x = 0; x < this-> k - 1; x++) yeni.set(this-> objects[0] * this-> objects[(y+1)*this-> k+x+1] - this-> objects[x+1] * this-> objects[(y+1)*this-> k]); | |
return yeni.determinant() / pow(this-> objects[0], this-> k - 2); | |
} | |
}; | |
int main() { | |
int n; | |
cout << "n'i girin: "; | |
cin >> n; | |
Matris matris(n); | |
n *= n; | |
cout << "toplam " << n << " tane sayi girin\n"; | |
for(int i=0,double p; i<n; i++) { | |
cin >> p; | |
matris.set(p); | |
} | |
cout << matris.determinant(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment