PROGRAM: /*GENERATION OF BAR-GRAPH*/ #include<stdio.h> #include #include #include<dos.h> void main() { int gd=DETECT,gm,n,i,i1=0; float data[100]={0},total=0; clrscr(); printf("\n\aEnter total number of values that form the input: "); scanf("%d",&n); printf("\n\aEnter the values..."); printf("\n\a===================\n"); for(i=0;i
OUTPUT OBTAINED:
PROGRAM: /*BRESENHAM’S CIRCLE*/ #include<stdio.h> #include #include<math.h> #include brescircle(float,float,float); plotcircle(float,float,float,float); void main() { float xc,yc,r; int gd=DETECT,gm; initgraph(&gd,&gm,""); cleardevice(); printf("\n\aEnter the co-ordinates of the centre of the circle: "); scanf("%f%f",&xc,&yc); printf("\nEnter the radius of the circle: "); scanf("%f",&r); brescircle(xc,yc,r); getch(); closegraph(); } brescircle(float xc,float yc,float r) { float p,x=0,y=r; p=3-2*r; while(x
putpixel(xc-x,yc+y,15); putpixel(xc+x,yc-y,15); putpixel(xc-x,yc-y,15); putpixel(xc+y,yc+x,15); putpixel(xc-y,yc+x,15); putpixel(xc+y,yc-x,15); putpixel(xc-y,yc-x,15); return; }
OUTPUT OBTAINED:
PROGRAM: /*CIRCLE USING PARAMETRIC EQUATION*/ #include<stdio.h> #include #include #include<math.h> void main() { int gd=DETECT,gm,xc,yc,x,y,r,i; initgraph(&gd,&gm,""); printf("\n\aEnter the co-ordinates of the centre of the circle: "); scanf("%d%d",&xc,&yc); printf("\nEnter the radius of the circle: "); scanf("%d",&r); cleardevice(); for(i=0;i<=360;i++) { x=xc+r*cos(3.14*i/180); y=yc+r*sin(3.14*i/180); putpixel(x,y,15); } getch(); }
OUTPUT OBTAINED:
PROGRAM: /*DDA ALGORITHM*/ #include<stdio.h> #include #include<stdlib.h> #include<math.h> #include void main() { int x1,y1,x2,y2,dx,dy,steps,xi,yi; char xs[10],ys[10],xe[10],ye[10]; double x,y; int gd=DETECT,gm,k; clrscr(); initgraph(&gd,&gm,""); printf("\n\aEnter co-ordinates of the line to be drawn: "); scanf("%d%d%d%d",&x1,&y1,&x2,&y2); dx=abs(x2-x1); dy=abs(y2-y1); if(abs(dx)>abs(dy)) steps=abs(dx); else steps=abs(dy); xi=dx/steps; yi=dy/steps; x=x1; y=y1; putpixel(floor(x),floor(y),10); for(k=1;k<=steps;k++) { x=x+xi; y=y+yi; putpixel(floor(x),floor(y),10); } getch(); closegraph(); }
OUTPUT OBTAINED:
PROGRAM: /*DRAWING AN ELLIPSE*/ #include<stdio.h> #include #include<math.h> #include void ellips(int,int,int,int); void main() { int gd=DETECT,gm,xc,yc,sa,ea,r1,r2; initgraph(&gd,&gm,""); cleardevice(); printf("\n\aEnter the co-ordinates of the centre of the ellipse: "); scanf("%d%d",&xc,&yc); printf("\n\aEnter the radii of the ellipse: "); scanf("%d%d",&r1,&r2); ellips(xc,yc,r1,r2); getch(); closegraph(); } void ellips(int xc,int yc,int r1,int r2) { float rad; int x,y,i; for(i=0;i<360;i++) { rad=3.14*i/180; x=xc+r1*cos(rad); y=yc+r2*sin(rad); putpixel(x,y,10); } return; }
OUTPUT OBTAINED:
PROGRAM: /*CIRCLE USING PARAMETRIC EQUATION: TAKING RADIUS TWICE*/ #include<stdio.h> #include #include #include<math.h> void main() { int gd=DETECT,gm,xc,yc,x,y,rx,ry,i; initgraph(&gd,&gm,""); printf("\n\aEnter the co-ordinates of the centre of the circle: "); scanf("%d%d",&xc,&yc); printf("\n\aEnter the radius of the circle twice: "); scanf("%d%d",&rx,&ry); cleardevice(); for(i=0;i<=360;i++) { x=xc+rx*cos(3.14*i/180); y=yc+ry*sin(3.14*i/180); putpixel(x,y,10); setfillstyle(SOLID_FILL,2); } getch(); }
OUTPUT OBTAINED:
PROGRAM: /*PIE-CHART*/ #include<stdio.h> #include #include<math.h> #include void main() { int gd=DETECT,gm,i,n,sa=0,ea,r=150; float data[20],total=0; clrscr(); initgraph(&gd,&gm,""); printf("\n\aEnter the total number of values to be entered: "); scanf("%d",&n); printf("\n\aEnter the values one-by-one...\n"); for(i=1;i<=n;i++) { scanf("%f",&data[i]); total=total+data[i]; } for(i=1;i<=n;i++) { ea=data[i]; ea=ea+sa; if(i==n) ea=360; setfillstyle(i+1,i+1); pieslice(320,240,sa,ea,r); sa=ea; } getch(); closegraph(); }
OUTPUT OBTAINED:
PROGRAM:
/*REFLECTION OF AN OBJECT*/ #include<stdio.h> #include #include<math.h> #include int x0=320,y0=240; int t[3][2]={100,100,150,50,50,50}; void main() { int gd=DETECT,gm,ch; initgraph(&gd,&gm,""); do { cleardevice(); gotoxy(1,10); printf("\n\a1. ORIGINAL\n2. REFLECTION\n3. EXIT"); printf("\n\aEnter your choice: "); scanf("%d",&ch); if(ch==1) { cleardevice(); triangle(0,1,1,1); getch(); } if(ch==2) reflect(); }while(ch!=3); closegraph(); } triangle(int i,int j,int rx,int ry) { line(x0,0,x0,2*y0); line(0,y0,2*x0,y0); line(x0+t[0][i]*rx,y0-t[0][j]*ry,x0+t[1][i]*rx,y0-t[1][j]*ry); line(x0+t[1][i]*rx,y0-t[1][j]*ry,x0+t[2][i]*rx,y0-t[2][j]*ry); line(x0+t[2][i]*rx,y0-t[2][j]*ry,x0+t[0][i]*rx,y0-t[0][j]*ry); return; } reflect() { int ch; printf("\n1. X-axis\n2. Y-axis\n3. ORIGIN\n4. y=x\n5. y=-x"); printf("\nEnter your choice: "); scanf("%d",&ch); cleardevice(); triangle(0,1,1,1); if(ch==1) triangle(0,1,1,-1); if(ch==2) triangle(0,1,-1,1); if(ch==3) triangle(0,1,-1,-1); if(ch==4) triangle(1,0,1,1);
if(ch==5) triangle(1,0,-1,-1); getch(); return; }
OUTPUT OBTAINED: