GAUSS ELIMINATION

If you have any queries please leave a message here
Your Message
×



USING ARRAY

#include<stdio.h>
void main()
{
int n,i,j,k;
float array1[10][10],array2[10],temp;
printf("\nEnter the number of equation present...");
scanf("%d",&n);

//Input values present in the equations as mention
for(i=0;i<n;i++)
{
printf("\nEnter Equation %d",(i+1));
for(j=0;j<n;j++)
{
printf("\nEnter the value attach with x%d...",(j+1));
scanf("%f",&array1[i][j]);
}
printf("\nEnter the value which is present after '=' symbol...");
scanf("%f",&array2[i]);
}

//Doing calculation using Gauss Elimination Method
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
temp = array1[j][i] / array1[i][i];
for(k=0;k<n;k++)
{
if(k==i)
array1[j][k] = 0;
else
array1[j][k] = array1[j][k] - (array1[i][k] * temp);
}
array2[j] = array2[j] - (array2[i] * temp);
}
}

//After calculation print result in matrix format
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\t%f",array1[i][j]);
}
printf("\t=\t%f\n",array2[i]);
}

//Calculate the values of x1, x2, x3, . . . etc.
for(i=n-1;i>=0;i--)
{
for(j=n-1;j>=i;j--)
{
if(j==i)
array2[i] = array2[i] / array1[i][j];
else
array2[i] = array2[i] - (array1[i][j] * array2[j]);
}
printf("\nx%d = %f",(i+1),array2[i]);
}
}


USING POINTER

#include<stdio.h>
void main()
{
int n,i,j,k;
float *array1,*array2,temp;
printf("\nEnter the number of equation present...");
scanf("%d",&n);

//Dynamic memory allocation
array1=(float *)malloc(n * n * sizeof(float));
array2=(float *)malloc(n * sizeof(float));

//Input values present in the equations as mention
for(i=0;i<n;i++)
{
printf("\nEnter Equation %d",(i+1));
for(j=0;j<n;j++)
{
printf("\nEnter the value attach with x%d...",(j+1));
scanf("%f",(array1 + i*n + j));
}
printf("\nEnter the value which is present after '=' symbol...");
scanf("%f",(array2 + i));
}

//Doing calculation using Gauss Elimination Method
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
temp = *(array1 + j*n + i) / *(array1 + i*n + i);
for(k=0;k<n;k++)
{
if(k==i)
*(array1 + j*n + k) = 0;
else
*(array1 + j*n + k) = *(array1 + j*n + k) - (*(array1 + i*n + k) * temp);
}
*(array2 + j) = *(array2 + j) - (*(array2 + i) * temp);
}
}

//After calculation print result in matrix format
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\t%f",*(array1 + i*n + j));
}
printf("\t=\t%f\n",*(array2 + i));
}

//Calculate the values of x1, x2, x3, . . . etc.
for(i=n-1;i>=0;i--)
{
for(j=i;j<n;j++)
{
if(j==i)
*(array2 + i) = *(array2 + i) / *(array1 + i*n + j);
else
*(array2 + i) = *(array2 + i) - (*(array1 + i*n + j) * *(array2 + j + 1));
}
printf("\nx%d = %f",(i+1),*(array2 + i));
}
}



ABOUT US

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.


MORE TOPIC


Windows Command

UNIX Command

IGNOU Assignment Solution

IGNOU Question Paper Solution

Solutions of Different Questions


WHAT WE DO


Website Devlopment

Training

Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


CONTACT US


Follow Us