Posts

Analysis of Algorithm Computer Graphics Data Structures

Midpoint Ellipse Generation using C

Image
This is only the code and output explanation will follow soon! stay tuned!! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #include<conio.h> #include<stdio.h> #include<graphics.h> float r,d; int xc,x,yc,y; void main () { int gd=DETECT,gm; initgraph(&gd,&gm, "C:\\TURBOC3\\BGI" ); printf( "Enter radius: " ); scanf( "%f" ,&r); printf( "Enter coords of center:" ); scanf( "%d%d" ,&xc,&yc); x= 0 ; y=r; putpixel(xc+x,yc+y, 2 ); d = 1.25 - r; do { if (d< 0 ) { x++; d = d+ 2 *x+ 1 ; } else { x++; y--; d = d+ 2 *x- 2 *y+ 1 ; } printf( "%f %d %d\n" ,d,x,y); putpixel(xc+x,yc+y, 2 ); putpixel(xc-x,yc+y, 3 ); putpixel(xc+x,yc-y, 4 ); putpixel(xc-x,yc-y, 5 ); putpixel(xc+y,yc+x, 6 ); putpixel(xc-y,yc+x, 7 ); putpixel(xc+y,yc-x, 8...

Cohen Sutherland Line Clipping Algorithm In C

Image
This is only the code and the output. Explanation of the code will follow soon. Stay Tuned!! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 #include<conio.h> #include<stdio.h> #include<graphics.h> #include<math.h> void bytecode (); void sutherland (); int a[ 4 ],b[ 4 ]; float m,xnew,ynew; float xl = 100 , yl = 100 , xh = 300 , yh = 300 ,xa = 10 ,ya = 200 ,xb = 250 , yb = 150 ; void main () { int gd = DETECT,gm; initgraph(&gd,&gm, "C:\\TURBOC3\\BGI" ); setcolor( 5 ); line(xa,ya,xb,yb); se...

Longest Common Subsequence using Dynamic Programming in C

Image
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 #include<stdio.h> #include<conio.h> #include<string.h> #define SIZE 20 void display ( char [][SIZE], char [], int , int ); void compute_LCS ( char A[], char B[]) { int m,n,i,j; int c[SIZE][SIZE]; char d[SIZE][SIZE]; m=strlen(A); n=strlen(B); for (i= 0 ;i<=m;i++) c[ 0 ][i]= 0 ; for (i= 0 ;i<=n;i++) c[i][ 0 ]= 0 ; for (i= 1 ;i<=m;i++) { for (j= 1 ;j<=n;j++) { if (A[i]==B[j]) { c[i][j]=c[i- 1 ][j- 1 ]+ 1 ; d[i][j]= '/' ; } else if (c[i- 1 ][j]>=c[i][j- 1 ]) { c[i][j]=c[i- 1 ][j]; d[i][j]= '^' ; } else { c[i][j]=c[i][j- 1 ]; d[i][j]= '<' ; } } } printf( "\nTable is...\n...

Graph Coloring using Backtracking in C

Image
In this, we have been given a graph G and "m" colors. We have to colour out graph in such a way that NO 2 ADJACENT NODES, i.e nodes that are connected by an edge, have the same color. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 #include<conio.h> #include<stdio.h> int g[ 10 ][ 10 ],color[ 10 ],n; int main () { void graph( int k); void display(); int e,i,j,v1,v2; //making an adjacency matrix printf( "Enter no of vertices:" ); scanf( "%d" ,&n); printf( "Enter no of edges:" ); scanf( "%d" ,&e); for (i= 0 ;i<n;i++) { color[i] = 0 ; //setting colors of all vertices to 0 for (j= 0 ;j<n;j++) { g[i][j] = 0 ; } } printf( "Enter edges: " ); for (i= 1 ;i<=e;i++) { scanf( "%d%d" ,&v1,&v2); g[v1][v2...

All Pairs Shortest Path Using C programming

Given a directed, connected weighted graph  G ( V , E ) , for each edge  ⟨ u , v ⟩ ∈ E , a weight  w ( u , v )  is associated with the edge. The  all pairs of shortest paths problem  (APSP) is to find a shortest path from  u  to  v  for every pair of vertices  u  and  v  in  V  . 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 #include<conio.h> #include<stdio.h> int n,i,j,k,cost[ 10 ][ 10 ]; void apsp ( int [ 10 ][ 10 ]); int min ( int , int ); void main () { // here we accept the cost matrix: printf( "Enter the no of vertices: " ); scanf( "%d" ,&n); printf( "Enter the cost adjacency matrix: " ); for (i= 1 ;i<=n;i++) { for (j= 1 ;j<=n;j++) { scanf( "%d...