main
|
Last change
on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | #include<stdio.h>
|
|---|
| 2 | int main()
|
|---|
| 3 | {
|
|---|
| 4 | int i,j,k,n;
|
|---|
| 5 | float A[20][20],c,x[10],sum=0.0;
|
|---|
| 6 | printf("\nEnter the order of matrix: ");
|
|---|
| 7 | scanf("%d",&n);
|
|---|
| 8 | printf("\nEnter the elements of augmented matrix row-wise:\n\n");
|
|---|
| 9 | for(i=1; i<=n; i++)
|
|---|
| 10 | {
|
|---|
| 11 | for(j=1; j<=(n+1); j++)
|
|---|
| 12 | {
|
|---|
| 13 | printf("A[%d][%d] : ", i,j);
|
|---|
| 14 | scanf("%f",&A[i][j]);
|
|---|
| 15 | }
|
|---|
| 16 | }
|
|---|
| 17 | for(j=1; j<=n; j++) /* loop for the generation of upper triangular matrix*/
|
|---|
| 18 | {
|
|---|
| 19 | for(i=1; i<=n; i++)
|
|---|
| 20 | {
|
|---|
| 21 | if(i>j)
|
|---|
| 22 | {
|
|---|
| 23 | c=A[i][j]/A[j][j];
|
|---|
| 24 | for(k=1; k<=n+1; k++)
|
|---|
| 25 | {
|
|---|
| 26 | A[i][k]=A[i][k]-c*A[j][k];
|
|---|
| 27 | }
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 | x[n]=A[n][n+1]/A[n][n];
|
|---|
| 32 | /* this loop is for backward substitution*/
|
|---|
| 33 | for(i=n-1; i>=1; i--)
|
|---|
| 34 | {
|
|---|
| 35 | sum=0;
|
|---|
| 36 | for(j=i+1; j<=n; j++)
|
|---|
| 37 | {
|
|---|
| 38 | sum=sum+A[i][j]*x[j];
|
|---|
| 39 | }
|
|---|
| 40 | x[i]=(A[i][n+1]-sum)/A[i][i];
|
|---|
| 41 | }
|
|---|
| 42 | printf("\nThe solution is: \n");
|
|---|
| 43 | for(i=1; i<=n; i++)
|
|---|
| 44 | {
|
|---|
| 45 | printf("\nx%d=%f\t",i,x[i]); /* x1, x2, x3 are the required solutions*/
|
|---|
| 46 | }
|
|---|
| 47 | return(0);
|
|---|
| 48 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.