This is mainly the concept of the program what to do in upper triangular program.
We take 3 for loops
for(k=0; k < n-1;k++)
{
for(p=k+1; p < n; p++)
{
if(a[k][k]==0 )
{
for(x=0; x < n;x++)
{
t=a[k][x];
a[k][x]=a[k+1][x];
a[k+1][x]=t;
}
continue;
}
}
i=0;
for(i=k+i;i < n-1;i++)
{
for(j=0;j < n-k;j++)
{
t1=a[k][k];
t2=a[i+1][k];
a[i+1][j+k]=t1*a[i+1][j+k]-t2*a[k][j+k];
}
}
}
Now in this the the inner most loop which is j loop is for doing the row operation.
i loop is for going to the next row,and the k loop is for making the elements 0 in the next collumn ,i.e, making the elements 0 in the first collumn we have to make the elements 0 of the second collumn.
No comments:
Post a Comment