upsidedown

gauss_elimntn

Sep 9th, 2011
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include<stdio.h>
  2. void main()
  3. {
  4.     int a[3][4],i,j,temp,x,y,z;
  5.     printf("enter the coefficients of the 3 equations of type ax+by+cz=d to find values of x,y,z\n");
  6.     for(i=0;i<3;i++)
  7.     {
  8.         printf("enter the values of a,b,c,d for equation:%d\n",i+1);
  9.         for(j=0;j<4;j++)
  10.         {
  11.             scanf("%d",&a[i][j]);
  12.         }
  13.     }
  14.     for(i=1;i<3;i++)
  15.     {
  16.         temp=a[i][0];
  17.         for(j=0;j<4;j++)
  18.             a[i][j]=(a[0][0]*a[i][j])-(temp*a[0][j]);
  19.     }
  20.     temp=a[2][1];
  21.     for(j=0;j<4;j++)
  22.         a[2][j]=(a[1][1]*a[2][j])-(temp*a[1][j]);
  23.     printf("the upper triangular matrix is\n");
  24.     for(i=0;i<3;i++)
  25.     {
  26.         for(j=0;j<4;j++)
  27.         {
  28.             printf("%d\t",a[i][j]);
  29.         }
  30.         printf("\n");
  31.     }
  32.     z=a[2][3]/a[2][2];
  33.     y=(a[1][3]-a[1][2]*z)/a[1][1];
  34.     x=((a[0][3]-a[0][2]*z)-(a[0][1]*y))/a[0][0];
  35.     printf("the values are x=%d \ny=%d \nz=%d \n",x,y,z);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment