Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. /*--------------------------------------------------------*
  2. * Main Program *
  3. * This program solves a system of linear equations *
  4. * using simple Gaussian elimination method *
  5. *---------------------------------------------------------*
  6. * Functions invoked *
  7. * NIL *
  8. *---------------------------------------------------------*
  9. * Subroutines used *
  10. * GAUSS1 *
  11. *---------------------------------------------------------*
  12. * Variables used *
  13. * n - Number of equations in the system *
  14. * a - Matrix of coefficients *
  15. * b - Right side vector *
  16. * x - Solution vector *
  17. *---------------------------------------------------------*
  18. * status - Solution status *
  19. *---------------------------------------------------------*/
  20.  
  21. main()
  22. {
  23. int status,n,i,j;
  24. float a[10][10],b[10],x[10];
  25.  
  26. printf("\n SOLUTION BY SIMPLE GAUSS METHOD \n");
  27.  
  28. printf("What is the size of the system(n)? \n");
  29. scanf("%d", &n);
  30.  
  31. printf("Input coefficients a(i,j), row-wise, \n");
  32. printf("one row on each line. \n");
  33. for(i=1;i<=n;i++)
  34. for(j=1;j<=n;j++)
  35. scanf("%f", &a[i][j]);
  36. printf("\nInput vector b \n");
  37. for(i=1;i<=n;i++)
  38. scanf("%f", &b[i]);
  39.  
  40. /*obtain solution by simple Gauss elimination method */
  41.  
  42. /* call the subroutine gauss1() */
  43.  
  44. gauss1(n,a,b,x,&status);
  45.  
  46. if(status != 0)
  47. {
  48. printf("\nSOLUTION VECTOR X \n");
  49. printf("/nEnter vector b \n");
  50.  
  51. for(i=1;i<=n;i++)
  52. scanf("%f", &b[i]);
  53. gauss2(n,a,b,x);
  54. printf("\n SOLUTION VECTOR X \n");
  55. printf("\n");
  56. for(i=1;i<=n;i++)
  57. printf("\t %f", x[i]);
  58. printf("\n");
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement