fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. #include <stdio.h>
  7. #include <math.h>
  8. #include"iostream"
  9. #include"conio.h"
  10.  
  11. using namespace std;
  12. void print_matrix(int str,int stb,double **mass)//вывод матрицы в консоль
  13. {
  14. for(int i=0;i<str;i++)
  15. {
  16. for(int j=0;j<stb;j++)
  17. printf("a[%d][%d]=%f \t",i,j,mass[i][j]);
  18. printf("\n");
  19. }
  20. printf("\n");
  21. }
  22.  
  23. void print_x(int stb,double *x)//вывод значений неизвестных в консоль
  24. {
  25. for(int i=0;i<stb;i++)
  26. printf("x[%d]=%f \t",i,x[i]);
  27. printf("\n");
  28. }
  29.  
  30. int rotation(int cnt_str,double **mass,double *&x)
  31. {
  32. int i,j,k;
  33. x=new double [cnt_str];//выделение памяти для неизвестных
  34. //прямой ход методом вращений
  35. double a,b,c,s,t;
  36. for(i=0;i<cnt_str;i++)
  37. {
  38. for(j=i+1;j<cnt_str;j++)
  39. {
  40. b=mass[j][i];
  41. a=mass[i][i];
  42. c=a/sqrt(a*a+b*b);
  43. s=b/sqrt(a*a+b*b);
  44. for(k=i;k<cnt_str+1;k++)
  45. {
  46. t=mass[i][k];
  47. mass[i][k]=c*mass[i][k]+s*mass[j][k];
  48. mass[j][k]=-s*t+c*mass[j][k];
  49. }
  50. }
  51. }
  52. //обратный ход метод Гаусса
  53. for(i=cnt_str-1;i>=0;i--)
  54. {
  55. double summ=0.;
  56. for(j=i+1;j<cnt_str;j++)
  57. summ+=mass[i][j]*x[j];
  58. summ=mass[i][cnt_str]-summ;
  59. if(mass[i][i]==0)
  60. return 0;
  61. x[i]=summ/mass[i][i];
  62. }
  63. return 1;
  64. }
  65.  
  66. int main()
  67. {
  68. int str=0,stb=0;
  69. setlocale(LC_ALL,"Rus");
  70. cout<<"Введите количество уравнений в СЛАУ: ";
  71. cin>>str;
  72. cout<<"Введите количество неизвестных в СЛАУ: ";
  73. cin>>stb;
  74. stb+=1;
  75. double **mass=new double*[str];
  76. for (int i=0;i<str;i++)
  77. {
  78. mass[i]=new double[stb];
  79. for (int j=0;j<stb;j++)
  80. {
  81. if(j==stb-1)
  82. cout<<"B"<<i+1<<":";
  83. else
  84. cout<<"A"<<i+1<<j+1<<":";
  85. cin>>mass[i][j];
  86. }
  87.  
  88. }
  89. double *x;
  90.  
  91. if(rotation(str,mass,x)==1)//решение системы линейных уравнений методом вращений и печать результата при удачном выполнении
  92. {
  93. //print_matrix(str,stb,mass);
  94. print_x(str,x);//вывод результата
  95. }
  96. else{printf("Error rotation\n");}
  97.  
  98. for(int i=0;i<str;i++) delete []mass[i];
  99. delete []mass;
  100. delete []x;
  101.  
  102.  
  103. return 0;
  104. }
  105.  
  106. return 0;
  107. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:9:18: fatal error: conio.h: No such file or directory
 #include"conio.h"
                  ^
compilation terminated.
stdout
Standard output is empty