Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  gh
Language: C/C++
Code:
/*
 * cg.c
 *
 *  Created on: 28-Dec-2015
 *      Author: pict
 */

#include <graphics.h>
#include <stdio.h>
#include <math.h>
#include <conio.h>

int main()
{     int i;
     float x1,y1,x2,y2,dx,dy,xinc,yinc,steps,xn,yn;
     printf("nEnter Starting point of line: nX: ");
     scanf("%d",&x1);
     printf("nY: ");
     scanf("%d",&y1);
     printf("nEnter End point of line: nX: ");
     scanf("%d",&x2);
     printf("nY: ");
     scanf("%d",&y2);
     dx= x2-x1;
     dy= y2-y1;
     if(abs(dx)>abs(dy))
          steps=abs(dx);
     else steps=abs(dy);
     xinc=dx/steps;
     yinc=dy/steps;
     putpixel(x1,y1,4);
     for(i=0;i<steps;i++)
     {
          xn+=xinc;
          yn+=yinc;
          putpixel(xn,yn,4);
     }
     return 0;
}



          
Comments: