Thursday, January 30, 2014

Reflection in c language

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
    int gdriver=DETECT,gmode;
    int midx=350,midy=300;
    int x1,y1,x2,y2;
    int x,y,i;

    clrscr();
    initgraph(&gdriver,&gmode,"c:/tc/bgi");
    printf("\n Enter the 1st co-ordinate=");
    scanf("%d%d",&x1,&y1);
    printf("\n Enter the 2nd co-ordinate=");
    scanf("%d%d",&x2,&y2);
    clrscr();
    line(midx,midy-150,midx,midy+150);
    line(midx-150,midy,midx+150,midy);
    outtextxy(midx,midy," origin");
    printf("\n Before refelction");
    line(midx+x1,midy+y1,midx+x2,midy+y2);
    while(1)
    {
        printf("\n Press 1 for reflection about x-axis");
        printf("\n Press 2 for reflection about y-axis");
        printf("\n press 3 for exit");
        printf("\n Choice=");
        scanf("%d",&i);
        switch(i)
        {
            case 1: line(midx+x1,midy-y1,midx+x2,midy-y2);
                break;
            case 2: line(midx-x1,midy+y1,midx-x2,midy+y2);
                break;
            default: exit(1);

        }
    }
    getch();


}

No comments:

Post a Comment