Advertisement
orneto

sistemas lineares-triangularização com troca de linhas

Apr 2nd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5.  
  6.  
  7. int main() {
  8.     int n;
  9.     printf("digite o numero de equacoes: ");
  10.     scanf("%d", &n);
  11.     int a[n][n], i, j, k, b[4], aux[n], o, s, x=0;
  12.     int m;
  13.     for ( i=0; i<n; i++ ){
  14.         for ( j=0; j<n; j++ )
  15.         {
  16.           printf (" [%d][%d] = ", i, j);
  17.           scanf ("%d", &a[i][j]);
  18.         }
  19.         printf("\n");
  20.     }
  21.     for(k=0;k<n;k++){
  22.         for(i=k+1;i<n;i++){
  23.             while((a[k][k])==0){
  24.                 for(o=0;o<n;o++){
  25.                     aux[o]=a[o][k];                
  26.                 }
  27.                 for(o=0;o<n;o++){
  28.                     a[o][k]=a[o][k+1];
  29.                 }
  30.                 for(o=0;o<n;o++){
  31.                     a[o][k+1]=aux[o];
  32.                 }      
  33.             }
  34.             m=a[i][k]/a[k][k];
  35.             for(j=k;j<n;j++){
  36.                    a[i][j]=a[i][j]-m*a[k][j];
  37.             }
  38.             a[i][k]=0;
  39.             b[i]=b[i]-m*b[k];
  40.         }
  41.        
  42.        
  43.     }
  44.     for ( i=0; i<n; i++ ){
  45.         for ( j=0; j<n; j++ )
  46.         {
  47.           printf ("%d ", a[i][j]);
  48.         }
  49.         printf("\n");
  50.     }
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement