#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,j,k,n;
float a[10][10],x[10],sum,t;
clrscr();
printf("enter the value of n:");
scanf("%d",&n);
printf("enter the value of matrix in row:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
scanf("%f",&a[i][j]);
}
}
printf("matrix is ....\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
printf("%f\t",a[i][j]);
}
printf("\n");
}
for(j=1;j<=n-1;j++)
{
for(i=j+1;i<=n;i++)
{
t=a[i][j]/a[j][j];
for(k=1;k<=n+1;k++)
{
a[i][k]=a[i][k]-t*a[j][k];
}}}
printf("upper triangular matrix is ....\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
printf("%f\t",a[i][j]);
}
printf("\n");
}
printf("solution of x by using back word substitution....\n");
for(i=n;i>=1;i--)
{
sum=0;
x[i]=0;
for(j=1;j<=n;j++)
{
sum=sum+a[i][j]*x[j];
}
x[i]=(a[i][n+1]-sum)/a[i][i];
}
for(i=1;i<=n;i++)
{
printf("x%d=%f",i,x[i]);
printf("\n");
}
getch();
}
#include<conio.h>
#include<math.h>
void main()
{
int i,j,k,n;
float a[10][10],x[10],sum,t;
clrscr();
printf("enter the value of n:");
scanf("%d",&n);
printf("enter the value of matrix in row:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
scanf("%f",&a[i][j]);
}
}
printf("matrix is ....\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
printf("%f\t",a[i][j]);
}
printf("\n");
}
for(j=1;j<=n-1;j++)
{
for(i=j+1;i<=n;i++)
{
t=a[i][j]/a[j][j];
for(k=1;k<=n+1;k++)
{
a[i][k]=a[i][k]-t*a[j][k];
}}}
printf("upper triangular matrix is ....\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
printf("%f\t",a[i][j]);
}
printf("\n");
}
printf("solution of x by using back word substitution....\n");
for(i=n;i>=1;i--)
{
sum=0;
x[i]=0;
for(j=1;j<=n;j++)
{
sum=sum+a[i][j]*x[j];
}
x[i]=(a[i][n+1]-sum)/a[i][i];
}
for(i=1;i<=n;i++)
{
printf("x%d=%f",i,x[i]);
printf("\n");
}
getch();
}
Input/Output:
Enter the value of n:3
No comments:
Post a Comment