JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Untitled Page | JustPaste.app
about 1 month ago8 views
👨‍💻Programming
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <iostream.h>

void dda(float x1, float y1, float x2, float y2)
{
    float dx, dy, steps;
    float xinc, yinc;
    float x, y;
    int i;

    dx = x2 - x1;
    dy = y2 - y1;

    if (fabs(dx) > fabs(dy))
        steps = fabs(dx);
    else
        steps = fabs(dy);

    xinc = dx / steps;
    yinc = dy / steps;

    x = x1;
    y = y1;

    putpixel((int)(x + 0.5), (int)(y + 0.5), WHITE);

    for (i = 0; i < steps; i++)
    {
        x = x + xinc;
        y = y + yinc;

        putpixel((int)(x + 0.5), (int)(y + 0.5), WHITE);
    }
}

int main()
{
    int gd = DETECT, gm;
    float x1, y1, x2, y2;

    initgraph(&gd, &gm, "c:\\turboc3\\bgi");

    cout << "Enter x1,y1:";
    cin >> x1 >> y1;

    cout << "Enter x2,y2:";
    cin >> x2 >> y2;

    dda(x1, y1, x2, y2);

    outtextxy(10, 200, (char*)"DDA line drawing algorithm");

    getch();
    closegraph();

    return 0;
}
← Back to timeline