Question: Can someone convert this C++ program into C program? //Gauss seidel method #include #include #include using namespace std; int main() { cout.precision(4); cout.setf(ios::fixed); int n,i,j,k,flag=0,count=0;
Can someone convert this C++ program into C program?
//Gauss seidel method
#include
#include
#include
using namespace std;
int main()
{
cout.precision(4);
cout.setf(ios::fixed);
int n,i,j,k,flag=0,count=0;
cout<<" Enter the no. of equations ";
cin>>n; //Input no. of equations
double a[n][n+1]; //declare a 2d array for storing the elements of the augmented matrix
double x[n]; //declare an array to store the values of variables
double eps,y;
cout<<" Enter the elements of the augmented matrix row-wise: ";
for (i=0;i for (j=0;j<=n;j++) cin>>a[i][j]; cout<<" Enter the initial values of the variables: "; for (i=0;i cin>>x[i]; cout<<" Enter the accuracy upto which you want the solution: "; cin>>eps; for (i=0;i for (k=i+1;k if (abs(a[i][i]) for (j=0;j<=n;j++) { double temp=a[i][j]; a[i][j]=a[k][j]; a[k][j]=temp; } cout<<"Iter"< for(i=0;i cout<<"x"< cout<<" ----------------------------------------------------------------------"; do //Perform iterations to calculate x1,x2,...xn { cout<<" "< for (i=0;i { y=x[i]; x[i]=a[i][n]; for (j=0;j { if (j!=i) x[i]=x[i]-a[i][j]*x[j]; } x[i]=x[i]/a[i][i]; if (abs(x[i]-y)<=eps) //Compare the ne value with the last value flag++; cout< } cout<<" "; count++; }while(flag cout<<" The solution is as follows: "; for (i=0;i cout<<"x"< return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
