Friday, December 4, 2009

Pie Chart

#include
#include
#include
#include
#include"math.h"
#define round(a) (int)(a+0.5)
void pie(int stangle,int endangle,int radius,int z)
{
int i,x,y,x1,y1;
for(radius=0;radius<100;radius++)
{
for(i=stangle;i{
x=getmaxx()/2+round(radius*cos((3.142*i)/180));
y=getmaxy()/2+round(radius*sin((3.142*i)/(180)));
putpixel(x,y,z);
}
}
}

int main(void)
{
/* request auto detection */
int gdriver, gmode, errorcode,sum=0,i,n,data[10],z=1;
detectgraph(&gdriver,&gmode);
int stangle = 0, endangle = 0, radius = 100;
printf("enter the no. of data");
scanf("%d",&n);
one:
sum=0;
for(i=0;i { printf("\nenter the %age of data");
scanf("%d",&data[i]);
}
for(i=0;i sum=sum+data[i];

if(sum!=100)
{
printf("error in data entry ");
getch();
clrscr();
goto one;
}
/* initialize graphics and local variables */
initgraph(&gdriver,&gmode, "..\\bgi");

/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}

/* set fill style and draw a pie slice */
outtextxy(100,100,"PIE CHART");
for(i=0;i {
stangle=endangle;
endangle=stangle+round((data[i]*360)/100);
pie(stangle, endangle, radius,z);
z++;
}
/* clean up */
getch();
closegraph();
return 0;
}

No comments:

Post a Comment