Programmer's Wiki
Advertisement

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?[]

  1. Program enters the main()
  2. Variables a,b,c,x,y are declared
  3. Screen cleared
  4. Program asks you to enter details
  5. It shows entered value
  6. It enters for loop (1)
  7. There x value is initialized to -100 to start points from -100
  8. Then y value also done in same way
  9. The program checks whether it satisfies a*x+b*y+c=0 which is a basic line equation
  10. If it does it prints the value, otherwise it returns to for loop again
  11. In the same way,all value gets printed
  12. You may notice the presence of for loop again in (2),it is because at 1st, the program prints only y-major values.
  13. At (2) it prints x-major values
  14. Execution finished.

See also[]

Advertisement