You are on page 1of 3

Er.

puneet kumar tyagi

AIM :- Write a program for MATRIX METHOD


#include<stdio.h>

#include<conio.h>

main()

float ar[10][10],ar1[10],ans[10],d,s;

int i,j,n,q,w,e;

clrscr();

printf("\n enter the number of elements");

scanf("%d",&n);

for(i=0;i<n;i++)

for(j=0;j<n;j++)

printf("\ n enter matrix elements row-wise");

scanf("%f",& ar[i][j]);

for(i=0;i<n;i++)

printf("\ n enter second matrix elements");

scanf("%f", & ar1[i])

for(q=0;q<n;q++)
Er.puneet kumar tyagi
{

i=q;

d=ar[i][i];

for(j=0;j<n;j++)

ar[i][j]=ar[i][j]/d;

ar1[i]=ar1[i]/d;

for(i=q+1;i<n;i++)

s=ar[i][q];

for(j=0;j<n;j++)

ar[e][j]=ar[e][j]-s*ar[q][j];

ar1[e]=ar1[e]-s*ar1[q];

for(i=0;i<n;i++)

printf("\n\n");

for(j=0;j<n;j++)

printf("\t%f",ar[e][j]);

printf("\t%f",ar1[e]);
Er.puneet kumar tyagi
}

ans[n-1]=ar1[n-1];

for(w=n-2;w>=0;w--)

ans[w]=ar1[w];

for(e=w;e<n;e++)

ans[w]=ans[w]-ans[e+1]*ar[w][e+1];

for(i=0;i<n;i++)

printf("\n\n the valve of x%d=%f",i,ans[i]);

getch();