Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define MAKS 50
- int i, j, k, n, m;
- float A[MAKS][MAKS], B[MAKS];
- void title(){
- printf("======================\n");
- printf("Metode Eliminasi Gauss\nOleh : Mirra Ariesta AA\n");
- printf("======================\n");
- }
- void inputMatriks(){
- printf("Input ordo baris : ");
- scanf("%d",&n);
- printf("Input ordo kolom : ");
- scanf("%d",&m);
- printf("\n");
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- printf("A[%d][%d] = ",i,j);
- scanf("%f",&A[i][j]);
- }
- printf("B[%d] = ",i);
- scanf("%f",&B[i]);
- printf("\n");
- }
- }
- void pivot(int l){
- float c,temp;
- int y;
- awal:
- if(A[l][l]==1);
- else if(A[l][l]!=0&&A[l][l]!=1){
- c=1/A[l][l];
- for(j=0;j<m;j++){
- A[l][j]=c*A[l][j];
- }
- B[l]=c*B[l];
- }
- else{
- for(y=l+1;y<n;y++){
- if(A[y][l]!=0){
- for(j=0;j<m;j++){
- temp=A[y][j];
- A[y][j]=A[l][j];
- A[l][j]=temp;
- }
- temp=B[l];
- B[l]=B[y];
- B[y]=temp;
- outputMatriks();
- goto awal;
- }
- else
- continue;
- }
- printf("Sorry, Error..!!\n");
- exit(0);
- }
- }
- void obe1(int l){
- float h;
- for(i=l+1;i<n;i++){
- h=A[i][l]/A[l][l];
- for(j=l;j<m;j++){
- A[i][j]=A[i][j]-h*A[l][j];
- }
- B[i]=B[i]-h*B[l];
- }
- }
- void obe2(int l){
- float h;
- for(i=l-1;i>=0;i--){
- h=A[i][l]/A[l][l];
- for(j=l;j>=0;j--){
- A[i][j]=A[i][j]-h*A[l][j];
- }
- B[i]=B[i]-h*B[l];
- }
- }
- void outputMatriks(){
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- printf("%5.0f\t",A[i][j]);
- }
- printf("|%5.0f \n",B[i]);
- }
- printf("\n");
- }
- main(){
- int l;
- title();
- inputMatriks();
- outputMatriks();
- for(l=0;l<n;l++){
- pivot(l);
- obe1(l);
- }
- outputMatriks();
- for(l=n-1;l>=0;l--) {
- obe2(l);
- }
- outputMatriks();
- }
Advertisement
Add Comment
Please, Sign In to add comment