This page explains solving line equation and print plotting points and it is very easy !
C++ Program:
#include<iostream.h>
#include<conio.h>
using namespace std;
void main()
{
int a,b,c;
register int x,y;
clrscr();
cout<<"Enter the co-efficients of x,y & constant\n";
cin>>a>>b>>c;
cout<<"your equation is "<<a<<" x "<<b<<" y "<<c<<" =0\n";
for(x=-100;x<=100;x++)//---(1)
for(y=-100;y<=100;y++)
{
if(a*x+b*y+c==0)
cout<<"( "<<a<<" , "<<b<<" ) ";
}
for(y=-100;y<=100;y++)//---(2)
for(x=-100;x<=100;x++)
{
if(a*x+b*y+c==0)
cout<<"( "<<a<<" , "<<b<<" ) ";
}
getch();
}
// This program can be used to plot points of line
// Enter 'zero' when co-efficient is zero
How it works?
- Program enters the main()
- Variables a,b,c,x,y are declared
- Screen cleared
- Program asks you to enter details
- It shows entered value
- It enters for loop (1)
- There x value is initialized to -100 to start points from -100
- Then y value also done in same way
- The program checks whether it satisfies a*x+b*y+c=0 which is a basic line equation
- If it does it prints the value, otherwise it returns to for loop again
- In the same way,all value gets printed
- You may notice the presence of for loop again in (2),it is because at 1st, the program prints only y-major values.
- At (2) it prints x-major values
- Execution finished.