Pie Chart
Pie Chart
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
int midx,midy,dx,dy,i,value[20],n,degree=0,top,left;
long start,end;
char str[5];
initgraph(&gd,&gm,"C:\\TC\\BGI");
cleardevice();
printf("enter the no of slices\n");
scanf("%d",&n);
setcolor(MAGENTA);
rectangle(0,40,639,450);
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
setcolor(WHITE);
outtextxy(275,10,"PIE CHART");
midx=getmaxx()/2;
midy=getmaxy()/2;
start=end=0;
value[0]=0;
printf("enter the percentage\n");
for(i=1;i<=n;i++)
{
scanf("%d",&value[i]);
degree=degree+((long)value[i]*360)/100;
if(degree>360)
{
printf("percentage more than 100 % ...program\n");
getch();
exit(0);
}
}
if(degree<360)
{
printf("percentage less than 100 % ...program\n");
getch();
exit(0);
}
for(i=0;i<n;i++)
{
end=start+(long)(value[i+1]*360)/100;
setfillstyle(i+1,i+1);
pieslice(midx,midy,start,end,200);
itoa(value[i+1],str,10);
dx=midx+200*cos(((double)(start+end)/2)*(3.14f/180));
dy=midy+200*sin(((-1)*(double)(start+end)/2)*(3.14f/180));
outtextxy(dx,dy,str);
start=start+((long)value[i+1]*360)/100;
getch();
}
getch();
closegraph();
}