Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. void Kramer(double C[3][3],double D[3][1]);
  5. void method_cramer();
  6. void info_prog();
  7. int get_number(void);
  8.  
  9. int main(){
  10. setlocale(LC_CTYPE, "UKR");
  11. int input;
  12. cout<<endl;
  13. cout<<'\t'<<"Виберiть варiант для продовження програми :"<<endl;
  14. cout<<endl;
  15. cout<<"1. Ввести систему Крамера"<<endl;
  16. cout<<"2. Про програму"<<endl;
  17. cout<<"4. Вивести меню"<<endl;
  18. cout<<"3. Вихiд"<<endl;
  19. cout<<endl;
  20. cout<<"Введiть номер >> ";
  21. cin>> input;
  22. cout<<endl;
  23. switch (input){
  24. case 1:
  25. method_cramer();
  26. break;
  27. case 2:
  28. info_prog();
  29. break;
  30. case 3:
  31. cin.get();
  32. break;
  33. case 4:
  34. cout<<" У розробцi!";
  35. break;
  36. default:
  37. cout<<"Ви ввели не вiрно!"<<endl;
  38. break;
  39. }
  40. }
  41.  
  42. void method_cramer(void){
  43. setlocale(LC_ALL,"UKR");
  44. int i,j;
  45. double A[3][3],B[3][1];
  46. cout<<endl;
  47. cout<<"Введiть коефiцiєнт невiдомих x1,x2,x3 з 1-го по 3-го рiвняння :"<<endl;
  48. for(i=0;i<3;i++)
  49. for(j=0;j<3;j++)
  50. cin>>A[i][j];
  51. cout<<endl;
  52. cout<<"Введiть свободний член з 1-го по 3-го рiвняння :"<<endl;
  53. for (i=0;i<3;i++)
  54. cin>>B[i][0];
  55. cout<<endl;
  56. cout<<"Ваша дана система :";
  57. cout<<endl;
  58. if(A[0][1]>=0 && A[0][2]>=0)
  59. cout<<A[0][0]<<"x1"<<"+"<<A[0][1]<<"x2"<<"+"<<A[0][2]<<"x3"<<"="<<B[0][0]<<endl;
  60. if(A[0][1]>=0 && A[0][2]<0)
  61. cout<<A[0][0]<<"x1"<<"+"<<A[0][1]<<"x2"<<A[0][2]<<"x3"<<"="<<B[0][0]<<endl;
  62. if(A[0][2]>=0 && A[0][1]<0)
  63. cout<<A[0][0]<<"x1"<<A[0][1]<<"x2"<<"+"<<A[0][2]<<"x3"<<"="<<B[0][0]<<endl;
  64. if(A[0][1]<0 && A[0][2]<0)
  65. cout<<A[0][0]<<"x1"<<A[0][1]<<"x2"<<A[0][2]<<"x3"<<"="<<B[0][0]<<endl;
  66. if(A[1][1]>=0 && A[1][2]>=0)
  67. cout<<A[1][0]<<"x1"<<"+"<<A[1][1]<<"x2"<<"+"<<A[1][2]<<"x3"<<"="<< B[1][0]<<endl;
  68. if(A[1][1]>=0 && A[1][2]<0)
  69. cout<<A[1][0]<<"x1"<<"+"<<A[1][1]<<"x2"<<A[1][2]<<"x3"<<"="<<B[1][0]<<endl;
  70. if(A[1][2]>=0 && A[1][1]<0)
  71. cout<<A[1][0]<<"x1"<<A[1][1]<<"x2"<<"+"<<A[1][2]<<"x3"<<"="<<B[1][0]<<endl;
  72. if(A[1][1]<0 && A[1][2]<0)
  73. cout<<A[1][0]<<"x1"<<A[1][1]<<"x2"<<A[1][2]<<"x3"<<"="<<B[1][0]<<endl;
  74. if(A[2][1]>=0 && A[2][2]>=0)
  75. cout<<A[2][0]<<"x1"<<"+"<<A[2][1]<<"x2"<<"+"<<A[2][2]<<"x3"<<"="<<B[2][0]<<endl;
  76. if(A[2][1]>=0 && A[2][2]<0)
  77. cout<<A[2][0]<<"x1"<<"+"<<A[2][1]<<"x2"<<A[2][2]<<"x3"<<"="<<B[2][0]<<endl;
  78. if(A[2][2]>=0 && A[2][1]<0)
  79. cout<<A[2][0]<<"x1"<<A[2][1]<<"x2"<<"+"<<A[2][2]<<"x3"<<"="<<B[2][0]<<endl;
  80. if(A[2][1]<0 && A[2][2]<0)
  81. cout<<A[2][0]<<"x1"<<A[2][1]<<"x2"<<A[2][2]<<"x3"<<"="<<B[2][0];
  82. Kramer(A,B);
  83. }
  84.  
  85. void Kramer(double C[3][3],double D[3][1]){
  86. double det,det1,det2,det3,x1,x2,x3;
  87. cout<<endl;
  88. cout<<"Находження визначникiв :"<<endl;
  89. det=C[0][0]*C[1][1]*C[2][2]+C[1][0]*C[2][1]*C[0][2]+C[0][1]*C[1][2]*C[2][0]-C[0][2]*C[1][1]*C[2][0]-C[1][0]*C[0][1]*C[2][2]-C[0][0]*C[2][1]*C[1][2];
  90. cout<<endl;
  91. cout<<"Визначник матрицi системи = "<<det;
  92. det1=D[0][0]*C[1][1]*C[2][2]+D[1][0]*C[2][1]*C[0][2]+C[0][1]*C[1][2]*D[2][0]-C[0][2]*C[1][1]*D[2][0]-D[1][0]*C[0][1]*C[2][2]-D[0][0]*C[2][1]*C[1][2];
  93. cout<<endl;
  94. cout<<"Визначник 1 = "<<det1;
  95. det2=C[0][0]*D[1][0]*C[2][2]+C[1][0]*D[2][0]*C[0][2]+D[0][0]*C[1][2]*C[2][0]-C[0][2]*D[1][0]*C[2][0]-C[1][0]*D[0][0]*C[2][2]-C[0][0]*D[2][0]*C[1][2];
  96. cout<<endl;
  97. cout<<"Визначник 2 = "<<det2;
  98. det3=C[0][0]*C[1][1]*D[2][0]+C[1][0]*C[2][1]*D[0][0]+C[0][1]*D[1][0]*C[2][0]-D[0][0]*C[1][1]*C[2][0]-C[1][0]*C[0][1]*D[2][0]-C[0][0]*C[2][1]*D[1][0];
  99. cout<<endl;
  100. cout<<"Визначник 3 = "<<det3;
  101. cout<<endl;
  102. if(det!=0){
  103. x1=det1/det;
  104. x2=det2/det;
  105. x3=det3/det;
  106. cout<<"x1 ="<<x1<<endl;
  107. cout<<"x2 ="<<x2<<endl;
  108. cout<<"x3 ="<<x3<<endl;
  109. }
  110. else
  111. cout<<"Система немає розв'язкiв, тому що дорiвнює 0"<<endl;
  112. }
  113.  
  114. void info_prog(void){
  115. cout<<endl;
  116. cout<<"Версiя: 1.0"<<endl;
  117. cout<<"Автор програми: Шевчук Олександр"<<endl;
  118. cout<<"Авторськi права: (с) 2019"<<endl;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement