C GRAPHICS PROGRAMS
Before starting any graphics program in C just keep a syntax in your mind which will be required in every graphics program of C.
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,”C:\\TURBOC3\\bgi”);
}
So now move on to our programs………
1. C program to create a circle
#include<graphics>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr(); // clears the screen
int gd=DETECT,gm;
initgraph(&gd,&gm,”C:\\TURBOC3\\bgi”);
int x,y,radius;
printf(“Enter the radius of circle”);
scanf(“%d”,&radius);
printf(“Enter the x position of circle);
scanf(“%d”,&x);
printf(“Enter the y position of circle);
scanf(“%d”,&y);
circle(x,y,radius);
getch();
closegraph();
closegraph();
}
2. C program to create a line
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int gd=DETECT,gm;
initgraph(&gd,&gm,”C:\\turboc3\\bgi”);
int x1,y1,x2,y2;
printf(“Enter the x1 coordinate of rectangle”);
scanf(“%d”,&x1);
printf(“Enter the y1 coordinate of rectangle”);
scanf(“%d”,&y1);
printf(“Enter the x2 coordinate of rectangle”);
scanf(“%d”,&x2);
printf(“Enter the y2 coordinate of rectangle”);
scanf(“%d”,&y2);
cleardevice();
cleardevice();
line(x1,y1,x2,y2);
getch();
closegraph();
getch();
closegraph();
}
3. C program to create a rectangle
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int gd=DETECT,gm;
initgraph(&gd,&gm,”C:\\turboc3\\bgi”);
int left,top,right,bottom;
printf(“Enter the left coordinate of rectangle”);
scanf(“%d”,&left);
printf(“Enter the right coordinate of rectangle”);
scanf(“%d”,&right);
printf(“Enter the top coordinate of rectangle”);
scanf(“%d”,&top);
printf(“Enter the bottom coordinate of rectangle”);
scanf(“%d”,&bottom);
cleardevice();
cleardevice();
rectangle(left,top,right,bottom);
getch();
closegraph();
getch();
closegraph();
}
Comments :
Post a Comment