Advertisement
Guest User

khatri love shrestha

a guest
Feb 16th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 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. }
  33. printf("\nThe solution is:\n");
  34. for(i=1; i<=n; i++)
  35. {
  36. x[i]=A[i][n+1]/A[i][i];
  37. printf("\n x%d=%f\n",i,x[i]);
  38. }
  39. return(0);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement