#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();
}
rajat.sethi93
-3
Newbie Poster
Recommended Answers
Jump to PostWhere 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.
Jump to PostWe 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.
All 7 Replies
rajat.sethi93
-3
Newbie Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
rajat.sethi93
-3
Newbie Poster
rajat.sethi93
-3
Newbie Poster
NathanOliver
429
Veteran Poster
Featured Poster
DavidB
44
Junior Poster
rajat.sethi93
-3
Newbie Poster
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.