Created
June 25, 2015 09:25
-
-
Save kimitoboku/71bb80e8cfd62300c334 to your computer and use it in GitHub Desktop.
行列式
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<iomanip> | |
int main(int argc, char *argv[]){ | |
int n; | |
double input; | |
std::cout << "n次の正方行列? n:"; | |
std::cin >> n; | |
double a[n][n]; | |
for(int i=0;i<n;i++){ | |
for(int j=0;j<n;j++){ | |
std::cout << i+1 << "行" << j+1 << "列目:"; | |
std::cin >> input; | |
a[i][j] = input; | |
} | |
} | |
double buf; | |
for(int i=0;i<n;i++){ | |
for(int j=0;j<n;j++){ | |
buf = a[j][i]/a[i][i]; | |
if(i<j){ | |
for(int k=0;k<n;k++){ | |
a[j][k] = a[j][k] - a[i][k]*buf; | |
} | |
} | |
} | |
} | |
std::cout << std::fixed << std::setprecision(4); | |
double det=1.0; | |
for(int i=0;i<n;i++){ | |
det = det*a[i][i]; | |
} | |
std::cout << "行列式:" << det << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment