Write a C Program to perform Pendulum in graphics

By | 02.12.2016

Perform Pendulum in graphics


Write a C Program to perform Pendulum in graphics. Here’s simple Program to perform Pendulum in graphics in C Programming Language.


Below is the source code for C Program to perform Pendulum in graphics which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/*  C Program to perform Pendulum in graphics  */

#include<graphics.h> 
#include<conio.h> 
#include<dos.h> 
#include<process.h> 
int cx=300,cy=100,r=300;
int x=0,y,p;
int path(int dtn) {
        int x1,y1;
        setcolor(15);
        if(x>=y) {
                return 0;
        }
        cleardevice();
        if(dtn==1) {
                circle(cx+x,cy+y,20);
                line(cx,cy,cx+x,cy+y);
        } else {
                circle(cx-x,cy+y,20);
                line(cx,cy,cx-x,cy+y);
        }
        delay(10);
        if(kbhit()) 
                exit(0);
        x++;
        if(p<0) 
                p+=2*x+1; else {
                y--;
                p+=2*(x-y)+1;
        }
        x1=x;
        y1=y;
        path(dtn);
        cleardevice();
        if(dtn==1) {
                circle(cx+x1,cy+y1,20);
                line(cx,cy,cx+x1,cy+y1);
        } else {
                circle(cx-x1,cy+y1,20);
                line(cx,cy,cx-x1,cy+y1);
        }
        delay(10);
        if(kbhit()) 
                exit(0);
        return(0);
}
void main() {
        int gd=DETECT,gm=DETECT;
        initgraph(&gd,&gm,"");
        cleardevice();
        putpixel(300,100,4);
        while(1) {
                x=0;
                y=r;
                p=1-r;
                path(1);
                x=0;
                y=r;
                p=1-r;
                path(0);
        }
}

Above is the source code for C Program to perform Pendulums in graphics which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

2.7 3 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments