Advertisement
rootUser

GEM

Jun 13th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int i,j,k,n;
  5.     float A[20][20],c,x[10];
  6.     printf("\nEnter the size of matrix: ");
  7.     scanf("%d",&n);
  8.     printf("\nEnter the elements of augmented matrix row-wise:\n");
  9.     for(i=1; i<=n; i++)
  10.     {
  11.         for(j=1; j<=(n+1); j++)
  12.         {
  13.             printf(" A[%d][%d]:", i,j);
  14.             scanf("%f",&A[i][j]);
  15.         }
  16.     }
  17.     /* Now finding the elements of diagonal matrix */
  18.     for(j=1; j<=n; j++)
  19.     {
  20.         for(i=1; i<=n; i++)
  21.         {
  22.             if(i!=j)
  23.             {
  24.                 c=A[i][j]/A[j][j];
  25.                 for(k=1; k<=n+1; k++)
  26.                 {
  27.                     A[i][k]=A[i][k]-c*A[j][k];
  28.                 }
  29.             }
  30.         }
  31.     }
  32.     printf("\nThe solution is:\n");
  33.     for(i=1; i<=n; i++)
  34.     {
  35.         x[i]=A[i][n+1]/A[i][i];
  36.         printf("\n x%d=%f\n",i,x[i]);
  37.     }
  38.     return(0);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement