0% found this document useful (0 votes)
38 views

Practical No: 6 Date: Gauss Elimination Method Exercise

This C program uses Gauss elimination method to solve a system of 3 linear equations with 3 unknowns (x1, x2, x3): 2x1 + 8x2 + 2x3 = 14 x1 + 6x2 - x3 = 13 2x1 - x2 + 2x3 = 5 The program takes input of the coefficients, performs Gauss elimination to put the matrix in upper triangular form, and then uses back substitution to solve for the unknowns x1, x2, and x3. The solutions are then printed as the output.

Uploaded by

jaydip
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Practical No: 6 Date: Gauss Elimination Method Exercise

This C program uses Gauss elimination method to solve a system of 3 linear equations with 3 unknowns (x1, x2, x3): 2x1 + 8x2 + 2x3 = 14 x1 + 6x2 - x3 = 13 2x1 - x2 + 2x3 = 5 The program takes input of the coefficients, performs Gauss elimination to put the matrix in upper triangular form, and then uses back substitution to solve for the unknowns x1, x2, and x3. The solutions are then printed as the output.

Uploaded by

jaydip
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Enrollment No:180123116023

Practical No: 6 Date:


Gauss Elimination Method

Exercise:
1. Develop C Program of system of linear equations by using back substitution Method.

2x1 + 8x2 + 2x3 = 14


x1 + 6x2 — x3 = 13
2x1 — x2 + 2x3 = 5

Programme:
#include<stdio.h>
#include<stdlib.h>
void main()
{
int i,j,k,n;
float A[20][20],c,x[10],sum=0.0;
clrcsr();
printf("Enrollment Number: 180123116006\n");
printf("\nEnter the order of matrix: ");
scanf("%d",&n);
printf("\nEnter the elements of augmented matrix row-wise:\n\n");
for(i=1; i<=n; i++)
{
for(j=1; j<=(n+1); j++)
{
printf("A[%d][%d] : ", i,j);
scanf("%f",&A[i][j]);
}
}
for(j=1; j<=n; j++)
{
for(i=1; i<=n; i++)
{
if(i>j)
{
c=A[i][j]/A[j][j];
for(k=1; k<=n+1; k++)
{
A[i][k]=A[i][k]-c*A[j][k];
}
}
}
}
x[n]=A[n][n+1]/A[n][n];
Gandhinagar Institute of Technology 2140706 NSM CE
for(i=n-1; i>=1; i--)
{
sum=0;
for(j=i+1; j<=n; j++)
{
sum=sum+A[i][j]*x[j];
}
x[i]=(A[i][n+1]-sum)/A[i][i];
}
printf("\nThe solution is: \n");
for(i=1; i<=n; i++)
{
printf("\nx%d=%f\t",i,x[i]);
}
getch();
}

Output:

Gandhinagar Institute of Technology 2160706 NSM CE

You might also like