Source Code:
/*****************************************************Program: solution of linear algebraic equationsusing Gauss Jordan MethodLanguage used: CProgram written by Bibek SubediJuly 2, 2011Tribhuvan University*****************************************************/#include<stdio.h>int main(){double matrix[10][10],a,b;int i, j, k, n;printf("Enter the no of variables: ");scanf("%d", &n);printf("Enter the agumented matrix:\n");for(i = 0; i < n ; i++){for(j = 0; j < (n+1); j++){scanf("%lf", &matrix[i][j]);}}for(i = 0; i < n; i++){for(j = 0; j < n; j++){if(i != j){a = matrix[j][i];b = matrix[i][i];for(k = 0; k < n+1; k++){matrix[j][k] = matrix[j][k] - (a/b) * matrix[i][k];}}}}for(i = 0; i < n; i++){a = matrix[i][i];for(j = 0; j < n+1; j++){matrix[i][j] /= a;}}printf("The required solution is: \n\n");for(i = 0; i < n ; i++){printf("%c => %.2f", i+97, matrix[i][n]);printf("\n");}return 0;}
تعليقات: 0
إرسال تعليق