Click below to view this site using some new reading style

** Classic | Flipcard | Magazine | Mosaic | Sidebar | Snapshot | Timeslide **

Gauss Elimination Iteration Method

10:06 AM Posted In Edit This 0 Comments »

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define pf printf
#define sf scanf
main(){int n,i,j,k;
float a[20][20],x[20],m,s=0.0;
pf("enter the order of co eficient : \n");
sf("%d",&n);
pf("\nenter element of the augmented matrix : \n");
for(i=1;i<=n;i++){
for(j=1;j<=n+1;j++)
sf("%f",&a[i][j]);}
for(i=1;i<=n-1;i++){
                    for(j=i+1;j<=n;j++){
                                        m=a[j][i]/a[i][i];
                                        for(k=1;k<=n+1;k++)
                                        a[j][k]=a[j][k]-m*a[i][k];
                                        }
                                        }
pf("\nthe upper trianguler matrix is : \n");
for(i=1;i<=n;i++){
                  for(j=1;j<=n+1;j++)
                  pf("%4.3f \t",a[i][j]);
                  pf("\n");}
x[n]=a[n][n+1]/a[n][n];
for(i=n-1;i>=1;i--)
{
                   s=0.0;
                   for(j=i+1;j<=n;j++)
                   s=s+a[i][j]*x[j];
                   x[i]=(a[i][n+1]-s)/a[i][i];
                   }
pf("\n\nthe trianguler solution is : \n");
for(i=1;i<=n;i++)
pf("x[%d] = %4.3f\n",i,x[i]);
getch();
}
© Ramen Mukherjee

Thank You Miss Nishat Parveen Smile

0 comments: