C program to draw a line without using graphics
We already know that the general equation of a straight line is y = mx + c, where m is the slope of the line and c is the y-intercept. It is the most common form of the equation of a straight line that is mainly used in geometry. So, We use this straight-line equation to draw a line in a C Program without using graphics.
Program:
#include<stdio.h> #include<conio.h> #include<graphics.h> using namespace std; int pth (int x) { return 2*x-3; } void main() { int i,j,y; for (int x=-10;x <= 10;x++) { for ( i=-10;i <= x;i++) { if (i==x) { y=pth(x); cout<<"x="; cout<<x; cout<<"y="; cout<<y; for(j=-10;j<=y;j++) { if(j==y) cout << "*"; else cout << " "; } } } cout << "\n"; } cin.get(); return 0; getch(); }