Monthly Archives: October 2015

Computer Graphics : Midpoint Circle Drawing Algorithm

/*==== Midpoint Circle Drawing Algorithm ====/*

#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int i,r,x,y,xc,yc;
float d;
clrscr();
printf("\n====Midpoint Circle Drawing Algorithm====\n\n");
printf("Enter Radius : ");
scanf("%d",&r);
printf("Enter centre of circle : \n");
printf("Enter x-coordinate : \n");
scanf("%d",&xc);
printf("Enter y-coordinate :\n");
scanf("%d",&yc);
initgraph(&gd,&gm,"C:\\TC\\BGI");
d=1.25-r;
x=0;
y=r;
do
{
if(d<0)
{
x=x+1;
d=d+2*x+1;
}
else
{
x=x+1;
y=y-1;
d=d+(2*x)-(2*y)+10;
}
putpixel(xc+x,yc+y,7);
putpixel(xc-y,yc-x,8);
putpixel(xc+y,yc-x,9);
putpixel(xc-y,yc+x,10);
putpixel(xc+y,yc+x,11);
putpixel(xc-x,yc-y,12);
putpixel(xc+x,yc-y,13);
putpixel(xc-x,yc+y,14);
delay(10);
}
while(x<y);
getch();
}

Output :

Screenshot (2) Screenshot (3)

That’s All. P)
Happy C-ing.

-Aayush Shrivastava


Are you satisfied?

Sorting Algorithm: C implementation for Heap Sort Algorithm (With clear and different functions)

Below algorithm given by Ms. Ayushi Nigam.

/*===== HEAP SORT ALGORITHM WITH DIFFERENT FUNCTIONS=====*/

#include<stdio.h>
#include<conio.h>
void heapsort(int a[],int n);
void buildmaxheap(int a[],int n);
void heapify(int a[],int i,int n);
void main()
{
int i,n,a[20];
clrscr();
printf("Enter the no of elements :\n");
scanf("%d",&n);
printf("Enter the elements :\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
heapsort(a,n-1);
printf("Print the sorted elements :\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
getch();
}
void heapsort(int a[],int n)
{
int i,temp;
buildmaxheap(a,n);
for(i=n;i>=1;i--)
{
temp=a[0];
a[0]=a[i];
a[i]=temp;
n--;
heapify(a,0,n);
}
}
void buildmaxheap(int a[],int n)
{
int i;
for(i=n/2;i>=0;i--)
{
heapify(a,i,n);
}
}
void heapify(int a[],int i,int n)
{
int l,r,lg,temp;
l=2*i;
r=(2*i)+1;
if(l<=n && a[l]>a[i])
lg=l;
else
lg=i;
if(r<=n && a[r]>a[lg])
lg=r;
if(lg!=i)
{
temp=a[i];
a[i]=a[lg];
a[lg]=temp;
heapify(a,lg,n);
}
}

Output :

Untitled

That’s All. P)
Happy C-ing.

-Aayush Shrivastava


Are you satisfied?