Skip to main content

Posts

Showing posts from 2017

What is Divide And Conquer Technique

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) {   
import java.util.*; class Patternhill { public static void main(String rishabh[]) {int i,j,m=-1; int n,p; Scanner sc=new Scanner(System.in); System.out.println("enter a row number"); int k=sc.nextInt(); System.out.println("enter the number of hill but u will get in multiple of 2"); int l=sc.nextInt(); for(i=1;i<=k;i++) {     int u=l-1; int g=l-1; m=m+2; for(j=(k-i);j>=1;j--) { System.out.print(" "); } for(n=m;n>=1;n--) { System.out.print("*"); } while(u>=1){ for (j=(2*(k-i));j>=1;j--) { System.out.print(" "); } for(p=m;p>=1;p--) { System.out.print("*"); } u--;} while(g>=1){for (j=(2*(k-i));j>=1;j--) { System.out.print(" "); }g--;} System.out.println(""); } } }
[ 'id' => $senderId ], 'message' => [ 'text' => $answer ] ]; $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$accessToken); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_exec($ch); curl_close($ch); //based on http://stackoverflow.com/questions/36803518

DDA LINE DRAWING PROGRAM IN C

                        /*   DDA LINE DRAWING  */ #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> #define round(a) ((int)(a+0.5)) void main() { int gd=DETECT,gm,x1,y1,x2,y2,dx,dy,length,i; float xinc,yinc,x,y; initgraph(&gd,&gm,"c:\\tc\\bgi"); printf("enter the end point co ordinates of lines"); scanf("%d %d %d %d",&x1,&y1,&x2,&y2); x=x1; y=y1; dx=x2-x2; dy=y2-y1; if(abs(dx)>abs(dy)) { length=abs(dx); } else { length=abs(dy); } xinc=dx/(float)length; yinc=dy/(float)length; putpixel(round(x),round(y),RED); for(i=0;i<length;i++) { x=x+xinc; y=y+yinc; putpixel(round(x),round(y),RED); } getch(); }

POLYGON FORMATION IN C

                       /*  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(); }

Transformation of shapes in C

#include<stdio.h> #include<conio.h> #include<graphics.h> #include<stdlib.h> #include<math.h> #include<dos.h> void main() { again: int gd=DETECT,gm,n; double a[10][10],b[10][10],c[10][10]; int i,j,k,m,x1[10],y1[10],x[10],y[10],sx,sy; char ch; initgraph(&gd,&gm,"c:\\tc\\bgi"); printf("\nEnter the no of sides : "); scanf("%d",&n); if(n<3) {  printf("\nPolygon can not form\n");  goto exit;  getch(); } else {  for(i=1;i<=n;i++)  { printf("\nEnter the co-ordinates (x%d,y%d) : ",i,i); scanf("%d%d",&x[i],&y[i]);  }  cleardevice();  for(i=1;i<n;i++)  {  setcolor(RED);  line(320+x[i],240-y[i],320+x[i+1],240-y[i+1]);  }  setcolor(RED);  line(320+x[1],240-y[1],320+x[n],240-y[n]); } getch(); //again: printf("\nWhat you want to do : \n"); prin

MID POINT SUB DIVISION

MID POINT SUB DIVISION #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<math.h> #include<stdlib.h> int x_min,y_min,x_max,y_max; void mpsd(int,int,int,int); void main() { int x1,x2,y1,y2; int gdriver =DETECT,gmode; initgraph(&gdriver,&gmode,"C:\\tc\\BGI"); printf("Enter the value of window coordinate:"); scanf("%d %d %d %d",&x_min,&y_min,&x_max,&y_max); printf("Enter the coordinates of the view point:"); scanf("%d %d %d %d",&x1,&y1,&x2,&y2); cleardevice(); rectangle(x_min,y_min,x_max,y_max); mpsd(x1,y1,x2,y2); getch(); } void mpsd(int xa,int ya,int xb,int yb) { if(((xa>=x_min)&&(ya>=y_min)&&(xa<=x_max)&&(ya<=y_max))&&((xb>=x_min)&&(yb>=y_min)&&(xb<=x_max)&&(yb<=y_max))) { setcolor(RED); line(xa,ya,xb,yb); }  else

BUBBLE SORTING WITH GRAPHICAL REPRESENTATION

/ * BUBBLE SORTING WITH GRAPHICAL REPRESENTATION */ #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> void object(int,int,int); void bubble(int); void flow(int,int); void mixing(int,int); int a[10]; void main() {  int n,i,gd=0,gm=0;  clrscr();  printf("Enter the No of Elements : " );  scanf("%d",&n);  for(i=0;i<n;i++)  {   printf("Enter the %d Element : ",i+1);   scanf("%d",&a[i]);  }  initgraph(&gd,&gm,"c://tc//bgi");  settextstyle(3,0,1);  outtextxy(250,50,"GIVEN NUMBER");  for(i=0;i<n;i++)  {   object(100+i*50,150,a[i]);   getch();  }  bubble(n); /* for(i=0;i<n;i++)  {   object(100+i*50,350,a[i]);   getch();  }*/delay(500);  settextstyle(3,0,2);  outtextxy(400,400,"prepared by rishabh");  getch(); } void bubble(int n) {  int i,j,temp;  for(i=0;i<n;i++)   for(j=i;j<n-1;j++)    if(a[i]>a[j

Cohen sutherland polygon clipping in C

/*Cohen sutherland polygon clipping in c*/ #include<stdio.h> #include<conio.h> #include<graphics.h> void leftclip(); void rightclip(); void topclip(); void bottomclip(); int gd=DETECT,gm,Xmin,Ymin,Xmax,Ymax,x1,y1; void main() { int n,i=1,x[10],y[10]; initgraph(&gd,&gm,"c://tc//bgi"); printf("enter the Xmin,Ymin,Xmax,Ymax co ordinate of window port"); scanf("\n%d\t%d\t%d\t%d",&Xmin,&Ymin,&Xmax,&Ymax); printf("enter the no. of side of polygon u want to enter"); scanf("\n%d",&n); for(i=1;i<=n;i++) { printf("the co ordinates of sides are x[%d] y[%d]",i,i); scanf("\n%d\t%d",&x[i],&y[i]); } cleardevice(); rectangle(Xmin,Ymin,Xmax,Ymax); getch(); for(i=1;i<n;i++) { setcolor(i); line(x[i],y[i],x[i+1],y[i+1]); }  setcolor(2); line(x[1],y[1],x[n],y[n]); getch(); leftclip(); rightclip(); topclip(); bottomclip(); getch(); } void l

Bresenham circle drawing program in C

  /* This is the program for bresenham circle drawing  in C */ #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> void main() { int gdriver = DETECT,gmode,x,y,r,x1,y1; float e; initgraph(&gdriver,&gmode,"C:\\tc\\BGI"); printf("center co-ordinate of x and y position of circle:\n"); scanf("%d %d",&x,&y); printf("input the radius of circle:\n"); scanf("%d",&r); x1=1; y1=r; putpixel(x+0,y+r,RED); putpixel(x+r,y+0,RED); putpixel(x-0,y-r,RED); putpixel(x-r,y-0,RED); e=3-2*r;   while(x1<y1) { if(e<0) { x1=x1+1; e=e+4*x1+6; } else { x1=x1+1; y1=y1-1; e=e+4*(x1-y1)+10; }           putpixel(x+x1,y+y1,1); putpixel(x+y1,y+x1,2); putpixel(x-x1,y+y1,3); putpixel(x-y1,y+x1,4); putpixel(x-x1,y-y1,5); putpixel(x-y1,y-x1,6); putpixel(x+x1,y-y1,7); putpixel(x+y1,y-x1,8); delay(100); } getch(); } /*NOTE:-You have to change the graphics