#include<stdio.h>
#include<conio.h>
void main()
{
 float a[5][5],x[3];float t,s;
 int i,j,k;
 printf("enter a matrix of order 3*4");
 for(i=0;i<3;i++)
 {
  for(j=0;j<4;j++)
  {
  scanf("%f",&a[i][j]);
  }
 }
 for(i=0;i<3;i++)
 {
  for(j=0;j<4;j++)
  printf("%f ",a[i][j]);
  printf("\n");
 }
 for(i=0;i<=1;i++)
 {
  for(j=i+1;j<=2;j++)
  {
  t=a[j][i]/a[i][i];
  for(k=i;k<=3;k++)
  a[j][k]=a[j][k]-t*a[i][k];
  }
 }
 printf("The upper triangular matrix is as\n");
 for(i=0;i<3;i++)
 {
 for(j=0;j<4;j++)
 printf(" %f",a[i][j]);
 printf("\n");
 }
 for(i=2;i>=0;i--)
 {
  s=0.0;
  for(j=i+1;j<3;j++)
  {
   s=s+a[i][j]*x[j];
   x[i]=(a[i][3]-s)/a[i][i];
  }
 }
 printf("\nRoots of the equation are");
 for(i=0;i<=2;i++)
 printf(" %f",x[i]);
 getch();
}

Can any one help me with this??????????????

Where are you dividing?

Just before those statements, output the values used to figure out the denominator. For example, for line 43, display i and a[i][i]
Now figure out what that value should be and why it is zero.

can u get the errors out of it..............

its basically Guass elimination method

We wouldnt know where to start. Did you try printing out the values before you divide to see where you are dividing by 0 like WlatP suggested? Learning how to debug your code is an important part of becoming a programer.

Like WaltP already suggested, go through your code and find all the places where division occurs. I see it on lines 25 and 43. Insert a line or two before the division statements that check to see if the denominator is 0:
e.g. - if (a[i][i] == 0) printf("\nAttempted division by zero. Execution aborted.");return 0;

Or something like that. That way your program doesn't just crash.

In any case, you are not going to be able to solve this equation completely. To solve for N variables, you need N equations. You have a 3X4 matrix (I think), so you will not be able to solve uniquely for all the variables. Is your system 3X4? The a matrix is 5X5, the x vector is 3, and your comment for the data entry indicates a 3X4 system. Which is it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.