Divide and Conquer is a programming technique which makes the program more efficient to write. And this technique work on the concept of recursion to solve a problem step by step. Generally this technique work in three parts:- Divide:- Divide the problem into some subproblem. Conquer:- Conquer the subproblem by calling recursively until subproblem solved. Combine:- (Optional Step) Combine the subproblem solution. So, that we will get the final problem Solution. When the subproblems are large enough to solve recursively, we call the recursive case. Once the subproblem becomes small enough that we no longer recursive, we say that the recursion "bottom out" and that we have gotten down to the base case. Application of Divide and Conquer Quick Sort Strassen's algorithm for matrix multiplication Merge Sort Counting inversions Binary Search Finding Min and max Divide and Conquer Abstract Algorithm DAC(a,i,j) {
/* POLYGON FORMATION IN C */
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
int n,x[15],y[15],i;
printf("ENTER THE NUMBER OF SIDE OF POLYGON:\n");
scanf("%d",&n);
if(n<3)
{
printf("POLYGON CAN'T BE FORM\n");
getch();
exit(0);
}
else
{
for(i=1;i<=n;i++)
{
printf("ENTER THE CORDINATES OF THE POLYGON %d SIDE\n",i);
scanf("%d %d",&x[i],&y[i]);
}
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\tc\\BGI");
for(i=1;i<n;i++)
{
line(x[i],y[i],x[i+1],y[i+1]);
}
line(x[1],y[1],x[n],y[n]);
}
getch();
}
very easy program ..i like it bro
ReplyDelete