Community Sites
Create your own community website and start earning today !
It's Free !
 
Communities Members BookmarksPolls Fresher Jobs Funny Pictures MCA Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter




C++ Program to solve linear equation (3 variable) by gauss elimination method


Posted Date: 23 Mar 2008    Resource Type: Articles/Knowledge Sharing    Category: Computer & Technology

Posted By: ashish singh       Member Level: Diamond
Rating:     Points: 5



//program to solve linear equation (3 variable) by gauss elimination method
#include
#include
#include
#include
#include
#define r 3
#define c 4
void main()
{
clrscr();
float a[r][c];
int i,j;
textcolor(GREEN);
cprintf("PROGRAM TO SOLVE LINEAR EQUATIONS BY GAUSS ELIMINATION
METHOD");
cout<<"\n";
textcolor(BLUE);
cprintf("enter the values in given format");
cout<<"\n";
cprintf("a[0][0] x + a[0][1] y + a[0][2] z = a[0][3]");
cout<<"\n";
for( i=0;i {
for( j=0;j {
cout<<"enter a["< cin>>a[i][j];
cout<<"\n";
}
}
delay(10);
step:
clrscr();
cout<<"the values entered are :\n";
for( i=0;i {
for(j=0;j {
cout< cout<<"\t";
}
cout<<"\n";
}

float temp1=a[0][0];
for( j=0;j{

a[0][j]=a[0][j]/temp1;
}
cout<<"the values after step 1 :\n";
cprintf("on dividing R1 by ");cout<for( i=0;i {
for(int j=0;j {
cout< cout<<"\t";
}
cout<<"\n";
}

float temp2=a[1][0];
for( j=0;j{a[1][j]=a[1][j]-temp2*a[0][j]; }
cout<<"the values after step 2 :\n";
cprintf("on R2 - ");cout<for( i=0;i {
for(int j=0;j {
cout< cout<<"\t";
}
cout<<"\n";
}

float temp3=a[2][0];
for( j=0;j{a[2][j]=a[2][j]-temp3*a[0][j];}
cout<<"the values after step 3 :\n";
textcolor(GREEN);
cprintf("on R3 - ");cout<for( i=0;i {
for(int j=0;j {
cout< cout<<"\t";
}
cout<<"\n";
}

float temp4=a[2][1];
for(j=0;ja[2][j]=a[2][j]-temp4/a[1][1]*a[1][j];
cout<<"the values after step 4 :\n";
cprintf("on R3 - ");cout<for( i=0;i {
for(int j=0;j {
cout< cout<<"\t";
}
cout<<"\n";
}
cout<<"Please wait while system calculates the result..............\n";
float z=a[r-1][c-1]/a[r-1][c-2];
float y=(a[r-2][c-1]-a[r-2][c-2]*z )/a[r-2][c-3];
float x=(a[r-3][c-1]-a[r-3][c-2]*z-a[r-3][c-3]*y)/a[r-3][c-4];
delay(10000);
clrscr();
textcolor(GREEN);
cprintf("SOLUTION OF GIVEN SYSTEM OF EQUATIONS");
cout<<"\n";
cout<<"x = "<cout<<"\ny = "<cout<<"\nz = "<float ch;
cout<<"\n";
cprintf("Do you want to view steps again");cout<<"\n";
cprintf("press '1' else Press '2'");cout<<" ";cin>>ch;
if(ch==1)
goto step;
else
exit(0);
getch();
}

output:

enter the values in given format
a[0][0] x + a[0][1] y + a[0][2] z = a[0][3]
enter a[0][0] : 2

enter a[0][1] : 1

enter a[0][2] : 1

enter a[0][3] : 10

enter a[1][0] : 3

enter a[1][1] : 2

enter a[1][2] : 3

enter a[1][3] : 18

enter a[2][0] : 1

enter a[2][1] : 4

enter a[2][2] : 9

enter a[2][3] : 16

2 1 1 10
3 2 3 18
1 4 9 16
the values after step 1 :
on dividing R1 by 1
1 0.5 0.5 5
3 2 3 18
1 4 9 16
the values after step 2 :
on R2 - 3*R1
1 0.5 0.5 5
0 0.5 1.5 3
1 4 9 16
the values after step 3 :
on R3 - 1*R1
1 0.5 0.5 5
0 0.5 1.5 3
0 3.5 8.5 11
the values after step 4 :
on R3 - 7*R2
1 0.5 0.5 5
0 0.5 1.5 3
0 0 -2 -10
Please wait while system calculates the result..............

SOLUTION OF GIVEN SYSTEM OF EQUATIONS
x = 7
y = -9
z = 5
Do you want to view steps again
press '1' else Press '2'




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: //C++ Program for newton forward interpolation formula
Previous Resource: C++ PROGRAM FOR INTEGRATION USING NUMERICAL METHODS
Return to Discussion Resource Index
Post New Resource
Category: Computer & Technology


Post resources and earn money!
 
Related Resources

Watch TV Channels



Contact Us    Editors    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.