Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <iomanip.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- double a[100][100], b[100], x[100], eps, rel;
- int i, j, k, size;
- int main()
- {
- //==Vvod_dannich==================================|
- cout<<"Vvedite razmernosy': "<<endl;
- cin>>size;
- cout<<"Vvedite trebyemtu tochnost': "<<endl;
- cin>>eps;
- cout<<"Vvedite elenenti massiva:"<<endl;
- for (i=0; i<size; i++)
- {
- for (j=0; j<size; j++)
- {
- cout<<"a["<<i+1<<"]["<<j+1<<"]=";
- cin>>a[i][j];
- cout<<endl;
- }
- }
- cout<<"Vvedite svobodnie chleni:"<<endl;
- for (i=0; i<size; i++)
- {
- cout<<"b["<<i+1<<"]="<<endl;
- cin>>b[i];
- }
- cout<<"Vvedennie dannie:"<<endl;
- cout<<"_________________________"<<endl;
- for (i=0; i<size; i++)
- {
- for (j=0; j<size; j++)
- {
- cout<<setw(3)<<a[i][j]<<" ";
- }
- cout<<setw(3)<<"|"<<setw(2)<<b[i]<<endl;
- }
- for (i=0; i<size; i++)
- {
- x[i]=0;
- }
- //==MZ============================================|
- double sum1, sum2, xN, m;
- int count=0;
- do
- {
- m=0;
- for (i=0; i<size; i++)
- {
- sum1=sum2=0;
- for (j=0; j<i; j++)
- {
- sum1 += a[i][j]*x[j];
- }
- for (j=i; j<size; j++)
- {
- sum2 += a[i][j]*x[j];
- }
- xN = x[i];
- x[i] -= (sum1+sum2-b[i])/a[i][i];
- if (fabs(xN-x[i])>m)
- {
- m=fabs(xN-x[i]);
- }
- }
- count++;
- }
- while (m>eps);
- if (m<eps)
- {
- for (i=0; i<size; i++)
- {
- printf("%f\n",x[i]);
- }
- }
- cout<<count<<" iteracsii"<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement