Siddhant
Siddhant
Output:
Program: - 02
[1]
02: Write a program to draw a circle using CG.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main () {
int gd = DETECT, gm;
int x = 250, y = 250, radius = 100;
initgraph (&gd, &gm, "c:\\turboc3\\bgi");
setcolor (RED);
circle (x, y, radius);
printf ("\n\n\n This output is produced by Siddhant Gahlot");
getch (); closegraph ();
return 0; }
Output:
Program: - 03
[2]
03: Write a program to draw a rectangle using CG.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main () {
int gd = DETECT, gm;
initgraph (&gd, &gm, "c:\\turboc3\\bgi");
setcolor (YELLOW);
rectangle (150, 100, 450, 350);
printf (“\n\n\n This output is produced by Siddhant Gahlot”);
getch (); closegraph ();
return 0; }
Output:
[3]
Program: - 04
04: Write a program to draw a shape of car using CG.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main ()
{
int gd = DETECT, gm;
initgraph (&gd, &gm,"c://turboc3//bgi");
cleardevice ();
Output:
[5]
Program: - 05
05: Write a program to draw a flag using CG.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main () {
int gd = DETECT, gm;
initgraph (&gd, &gm,"C:\\turboc3\\bgi");
setcolor (5);
Output:
Program: - 06
06: Write a program to draw a bar graph using CG.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
[7]
int main () {
int gd = DETECT, gm;
initgraph (&gd, &gm, "c:\\turboc 3\\bgi");
getch ();
closegraph ();
return 0; }
Output:
[8]
Program: - 07
07: Write a program to draw an ellipse using CG.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main () {
int gd = DETECT, gm;
initgraph (&gd, &gm, "c:\\turboc3\\bgi");
[9]
setcolor (YELLOW);
ellipse (320, 200, 0, 360, 50, 20);
printf (“\n\n\n This output is produced by Siddhant Gahlot”);
getch ();
closegraph ();
return 0; }
Output:
Program: - 08
08: Write a program to draw an arc using CG.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main ()
{
int gd = DETECT, gm;
[10]
initgraph (&gd, &gm, "c:\\turboc3\\bgi");
setcolor (YELLOW);
arc (200, 200, 180, 360, 40);
printf (“\n\n\n This output is produced by Siddhant Gahlot”);
getch ();
closegraph ();
}
Output:
Program: - 09
[11]
09: Write a program to draw a 2-D bar graph using CG.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main () {
int gd = DETECT, gm;
int left, top, right, bottom;
int i, bar_width = 40, gap = 20;
int values [] = {100, 200, 150, 180};
int n = sizeof (values) / sizeof (values [0]);
left = 60;
Output:
Program: - 10
[13]
10: Write a program to draw an ellipse with different colors
using CG.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main () {
getch ();
closegraph ();
return 0; }
Output:
[14]
Program: - 11
11: Write a program to draw a house using CG.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main () {
[15]
int gd = DETECT, g;
initgraph (&gd, &gm, "c:\\turboc3\\bgi");
Output:
[16]
Program: - 12
12: Write a program to draw a kite using CG.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main () {
[17]
int gd = DETECT, gm;
initgraph (&gd, &gm, "c:\\turboc3\\bgi");
setcolor (4);
Output:
[18]
Program: - 13
13: Write a program to draw a fish using CG.
#include<stdio.h>
#include<conio.h>
[19]
#include<graphics.h>
int main () {
int gd = DETECT, gm;
initgraph (&gd, &gm, "c:\\turboc3\\bgi");
ellipse (200, 200, 0, 360, 50, 30);
line (250, 200, 280, 170);
line (280, 170, 280, 230);
line (280, 230, 250, 200);
circle (170, 190, 3);
printf (“\n\n\n This output is produced by Siddhant Gahlot”);
getch ();
closegraph ();
return 0; }
Output:
[20]
Program: - 14
14: Write a program to draw a line using DDA algorithm.
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
int main () {
int gd = DETECT, gm, i;
float x, y, dx, dy, steps;
int x0, x1, y0, y1;
setbkcolor (GREEN);
x0 = 100; y0 = 200;
x1 = 500; y1 = 300;
dx = (float) (x1 - x0);
dy = (float) (y1 - y0);
steps = (fabs (dx) >= fabs (dy))? fabs (dx): fabs (dy);
dx = dx / steps;
dy = dy / steps;
x = x0;
y = y0;
[21]
for (i = 0; i <= steps; i++) {
putpixel (round(x), round(y), RED);
x += dx;
y += dy; }
Output:
[22]
Program: - 15
15: Write a program to draw a line using Bresenham’s
algorithm.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int drawline (int x0, int y0, int x1, int y1) {
int dx, dy, p, x, y;
dx = x1-x0;
dy = y1-y0;
x = x0;
y = y0;
p = 2*dy-dx;
while (x<x1) {
if (p >= 0) {
putpixel (x, y, 7);
y = y+1;
p = p+2*dy-2*dx; }
else {
putpixel (x, y, 7);
p = p+2*dy; }
x = x+1; }}
int main () {
int gd = DETECT, gm, error, x0, y0, x1, y1;
initgraph (&gd, &gm, "c:\\turboc3\\bgi");
printf (“\t This output is produced by Siddhant Gahlot”);
[23]
printf ("\n Enter co-ordinate of first point:");
scanf ("%d %d", &x0, &y0);
getch ();
closegraph ();
return 0; }
Output:
[24]
Program: - 16
16: Write a program to draw animation using increasing
circles filled with different colors and patterns.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
int main () {
int gd = DETECT, gm, i, x, y;
initgraph (&gd, &gm, "c:\\turboc3\\bgi");
x = getmaxx ()/3; y = getmaxx ()/3;
setcolor (BLUE);
for (i = 1; i <= 8; i++) {
setfillstyle (i, i); delay (20);
circle (x, y, i*20);
floodfill (x-2+i*20, y, BLUE); }
printf (“\n\n\n This output is produced by Siddhant Gahlot”);
getch (); closegraph ();
return 0; }
Output:
[25]
Program: - 17
17: Write a Program to make a moving-colored car using
inbuilt functions.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
int main () {
int gd = DETECT, gm, i, maxx, cy;
initgraph (&gd, &gm, "c:\\turboc3\\bgi");
setcolor (RED);
Output:
[27]
Program: - 18
18: Write a Program to implement Digital Clock.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
int main () {
int gd = DETECT, gm, hr, min, sec;
struct time t;
char str [10];
clrscr ();
setcolor (GREEN);
getch ();
closegraph ();
return 0; }
Output:
[29]
Program: - 19
19: Write a program to draw basic shapes.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main () {
int gd = DETECT, gm;
int poly [12] = {350, 450, 350, 410, 430, 400, 350, 350, 400, 310, 350,
450};
initgraph (&gd, &gm, "c:\\turboc3\\bgi");
setbkcolor (BLUE);
setcolor (YELLOW);
Output:
[31]
Program: - 20
20: Write a program to draw a pie chart using CG.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main () {
int gd = DETECT, gm, midx, midy;
initgraph (&gd, &gm,"c:\\turboc3\\bgi");
setcolor (WHITE);
outtextxy (275, 80, "PIE Chart");
[32]
printf (“This output is produced by Siddhant Gahlot”);
getch ();
closegraph ();
return 0; }
Output:
[33]