Saturday, June 30, 2012

64. DDA LINE DRAWING


//DDA LINE DRAWING
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float x,y,x1,y1,x2,y2,dx,dy,length;
int i,gd,gm;
clrscr();
printf("Enter the value of x1 :\t");
scanf("%f",&x1);
printf("Enter the value of y1 :\t");
scanf("%f",&y1);

63. BRESENHAM LINE DRAWING


//BRESENHAM LINE DRAWING
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float x,y,x1,y1,x2,y2,dx,dy,e;
int i,gd,gm;
clrscr();
printf("Enter the value of x1 :\t");
scanf("%f",&x1);
printf("Enter the value of y1 :\t");
scanf("%f",&y1);
printf("Enter the value of x2 :\t");
scanf("%f",&x2);

62. CODE CONVERSION IN 8086


ASCII ADJUSTMENT INSTRUCTIONS


CODE SEGMENT
ASSUME CS:CODE
START: MOV AX,31H 
ADD AX,39H 
AAA
ADD AX,3030H 
MOV BL,9
MOV AX,0702H 
AAD 

Thursday, June 28, 2012

61. 16-BIT DIVISION IN 8086


16-BIT DIVISION FOR SIGNED NUMBERS


DATA SEGMENT
NUM1 DW 4567H,2345H
NUM2 DW 4111H
QUO DW 2 DUP(0)
REM DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA

60. 8-BIT DIVISION IN 8086


8-BIT DIVISION FOR UNSIGNED NUMBERS


DATA SEGMENT
NUM1 DB 72H,
NUM2 DB 02H
QUO DB 1 DUP(0)
REM DB 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,NUM1 

Wednesday, June 27, 2012

59. DDA CIRCLE DRAWING IN C


//DDA CIRCLE DRAWING
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float x1,y1,x2,y2,startx,starty,epsilon;
int gd,gm,i,val,cx,cy;
int r;
clrscr();
clrscr();
printf("Enter the center coordinates of a circle :"); 
scanf("%d%d",&cx,&cy); 
clrscr();

58. BEIZER CURVE IN C


//BEIZER CURVE
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int x,y,z;
void main()
{
float u;
int gd,gm,ymax,i,n,c[4][3];
for(i=0;i<4;i++) { c[i][0]=0; c[i][1]=0; }
printf("\n\n Enter four points : \n\n");
for(i=0; i<4; i++)
{
printf("\t X%d Y%d : ",i,i);
scanf("%d %d",&c[i][0],&c[i][1]);
}

Tuesday, June 26, 2012

57. LIANG BARSKY LINE CLIPPING


//LIANG BARSKY LINE CLIPPING
#include<graphics.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int gd, gm ;
int x1 , y1 , x2 , y2 ;
int wxmin,wymin,wxmax, wymax ;
float u1 = 0.0,u2 = 1.0 ;
int p1 , q1 , p2 , q2 , p3 , q3 , p4 ,q4 ;
float r1 , r2 , r3 , r4 ;
int x11 , y11 , x22 , y22 ;
clrscr();
printf("Enter the windows left xmin , top boundry ymin\n");
scanf("%d%d",&wxmin,&wymin);
printf("Enter the windows right xmax ,bottom boundry ymax\n");
scanf("%d%d",&wxmax,&wymax);

56. COHEN SUTHERLAND LINE CLIPPING


//COHEN SUTHERLAND LINE CLIPPING
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>
typedef struct coordinate
{
int x,y;
char code[4];
}PT;
void drawwindow();
void drawline (PT p1,PT p2,int cl);
PT setcode(PT p);
int visibility (PT p1,PT p2);
PT resetendpt (PT p1,PT p2);
main()
{

55. SUTHERLAND HODGEMAN POLYGON CLIPPING


//SUTHERLAND HODGEMAN POLYGON CLIPPING
#include<stdio.h>
#include<graphics.h>
#include<math.h>
typedef struct
{
float x;
float y;
}PT;
int n;
main()
{
int i,j,gd,gm;
PT d,p1,p2,p[20],pi1,pi2,pp[20];
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"");
printf("Enter coordinates (left,top) of point1 : ");
scanf("%f%f",&p1.x,&p1.y);
printf("Enter coordinates (right,bottom) of point2 : ");
scanf("%f%f",&p2.x,&p2.y);
printf("Enter the number of vertex : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{

54. FLOOD FILL & BOUNDARY FILL ALGORITHM


//FLOOD FILL WITH EIGHT CONNECTED REGIONS
#include<stdio.h>
#include<graphics.h>
main()
{
int gd,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");
rectangle(50,50,100,100);
flood(55,55,4,15);
getch();
closegraph();
}
flood(seed_x,seed_y,foreground_col,background_col)
{

53. MIDPOINT CIRCLE DRAWING


//MIDPOINT CIRCLE
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float d;
int gd,gm,x,y,cy,cx;
int r;
clrscr();
printf("Enter the center coordinates of a circle :"); 
scanf("%d%d",&cx,&cy); 
clrscr();
printf("Enter the radius of a circle :");
scanf("%d",&r);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
x = 0;
y = r;

52. BRESENHAM CIRCLE DRAWING


//BRESENHAM CIRCLE
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float d;
int gd,gm,x,y,cy,cx;
int r;
clrscr();
printf("Enter the center coordinates of a circle :");
scanf("%d%d",&cx,&cy);
clrscr();
printf("Enter the radius of a circle :");
scanf("%d",&r);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
x = 0;
y = r;

51. 16 & 32-BIT ADDITIONS IN 8086


16-BIT ADDITION


DATA SEGMENT
NUM DW 1234H, 0F234H
SUM DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM 

50. 16-BIT MULTIPLICATION IN 8086



16-BIT MULTIPLICATION FOR UNSIGNED NUMBERS


DATA SEGMENT
NUM DW 1234H,1234H
PROD DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,NUM
MOV AX,[SI] 
MOV BX,[SI+2]

49. 16 & 32-BIT SUBTRACTIONS IN 8086



16-BIT SUBTRACTION

DATA SEGMENT
NUM DW 4567H,2345H
DIF DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME
CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
CLC

48. MATRIX MULIPLICATION

MOV SI,1000
       MOV BP,1020
       MOV DI,1050
L2:  MOV CX,00
L1:  MOV AL,[SI]
       MOV BL,[BP]
       MUL BL
       ADD CX,AX
       ADD BP,03
       INC SI

47. SEPARATING +VE & -VE NUMBERS

MOV SI,1100
      MOV CX,0A
      MOV AL,00
L2: MOV BX,[SI]
      ADD BX,00H
      JS L1
      INC SI
      INC AL

Monday, June 25, 2012

46. KOCH CURVE GENERATOR IN JAVA


//KOCH CURVE GENERATOR
import java.awt.*;
import java.awt.event.*;
public class Koch extends Frame
{  public static void main(String[] args){new Koch();}
   Koch()
   {  super("Koch. Click the mouse button to increase the level");
      addWindowListener(new WindowAdapter()
         {public void windowClosing(
                 WindowEvent e){System.exit(0);}});
      setSize (600, 500);
      add("Center", new CvKoch());
      show();
    }
}

Sunday, June 24, 2012

45. FTP PROTOCOL IN JAVA


Server Program:


import java.io.*;
import java.net.*;
public class Server
{
public static void main(String asd[]) throws Exception
{
ServerSocket ss=new ServerSocket(1024);
System.out.println(“ServerSocket Generated”);
Socket s=ss.accept();

44.UDP PROTOCOL IN JAVA


Server Program:

import java.io.*;
import java.net.*;
public class Server
{
public static void main(String str1[]) throws Exception
{
DatagramSocket ds;
byte[] buf=new byte[1024];
ds=new DatagramSocket(200);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter the String”);
InetAddress ia=InetAddress.getLocalHost();
while(true)
{

43. PRIORITY QUEUE USING HEAP


//PRIORITY QUEUE USING HEAP
#include<iostream.h>
#include<process.h>
#include<math.h>
#include<iomanip.h>
#include<malloc.h>
struct Heap
{
int capacity;
int size;
int *element;
};

42. HASHING TECHNIQUE IN C++



//HASHING TECHNIQUE
#include<iostream.h>
#include<iomanip.h>
struct listnode;
typedef struct listnode *position;
typedef position list;
struct hashtbl;
typedef struct hashtbl *hashtable;
hashtable initialize(int tablesize);
void destroytable(hashtable h);
position find(int key, hashtable h);
void insert(int key,hashtable h);
int retrieve(position p);
int hash(int key, int tablesize);

41. PRODUCER CONSUMER PROBLEM USING SEMAPHORE


//PRODUCER CONSUMER PROBLEM
#include<stdio.h>
#include<sys/types.h>
#include<sys/sem.h>
#include<stdlib.h>
#include<sys/shm.h>
#include<errno.h>
#include<sys/ipc.h>
void sem_acq(int);
void sem_rel(int);
int main()
{          int mutex,empty,full,shmid, n;
pid_t ret;
int in=-1,out=-1;
char *buffer;
char c[2];

40. KNAPSACK PROBLEM USING BACKTRACKING APPROACH



//KNAPSACK PROBLEM USING BACKTRACKING APPROACH
#include <stdio.h>
#include <conio.h>
#define max 10
int w[max],i,j,p[max];
int n,m;
float unit[max];
int y[max],x[max],fp=-1,fw;
void get()
{
printf(“\n Enter total number of items: “);
scanf(“%d”,&n);

39. CONVERSION OF COLOR MODELS


//CONVERSION OF COLOR MODELS
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float r,g,b,y,i,c,m,h,s,v;
int ch;
clrscr();
do
{

38. 2D REFLECTION & SHEAR IN C


//2D REFLECTION & SHEAR
#include<stdio.h>
#include<process.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void disp(int n,float c[][3])
{
float maxx,maxy;
int i;
maxx=getmaxx();
maxy=getmaxy();
maxx=maxx/2;
maxy=maxy/2;
i=0;
while(i<n-1)
{

37. 2D TRANSFORMATIONS IN C


//2D TRANSFORMATIONS
#include<stdio.h>
#include<process.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void disp(int n,float c[][3])
{
float maxx,maxy;
int i;
maxx=getmaxx();
maxy=getmaxy();
maxx=maxx/2;
maxy=maxy/2;
i=0;

36. MIDPOINT ELLIPSE DRAWING ALGORITHM

//MIDPOINT ELLIPSE DRAWING ALGORITHM
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
long d1,d2;
int i,gd,gm,x,y;
long rx, ry, rxsq,rysq,tworxsq,tworysq,dx,dy;
/* Read the radius x and y
---------------------------- */
printf("Enter the x radius of the ellipse :");
scanf("%ld",&rx);
printf("Enter the y radius of the ellipse :");
scanf("%ld",&ry);

35. OPTIMAL BINARY SEARCH TREE


//OPTIMAL BINARY SEARCH TREE
import java.io.*;
import java.util.*;
class Optimal
{
 public int p[];       
 public int q[];       
 public int a[];     
 public int w[][];
 public int c[][]; 
 public int r[][]; 
 public int n;             
 int front,rear,queue[];
 public Optimal(int SIZE)
 {
  p=new int[SIZE];
  q= new int[SIZE];
  a=new int[SIZE];
  w=new int[SIZE][SIZE];
  c=new int[SIZE][SIZE];
  r=new int[SIZE][SIZE];
  queue=new int[SIZE];
  front=rear=-1;
}

34. GRAPH COLORING PROBLEM


//GRAPH COLORING PROBLEM
import java.io.*;
import java.util.*;
class Gr_Color
{
 public int G[][],n,m,edges;
 int color_tab[];
 public Gr_Color(int MAX)
 {
System.out.println("\n\n\t Graph Coloring ");
G=new int[MAX][MAX];
  color_tab=new int[MAX];
for(int i=0;i<MAX;i++)
{
for(int j=0;j<MAX;j++)
{
 G[i][j]=0;
 color_tab[i]=0;
}
                }
}

Saturday, June 23, 2012

33. STRASSEN'S MATRIX MULTIPLICATION


//STRASSEN'S MATRIX MULTIPLICATION
import java.io.*;
public class Strassen
{
public static BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
public Strassen() throws IOException
{
int n;
int[][] a, b, c;
System.out.print("Enter the number or rows or colums: ");
n = Integer.parseInt(br.readLine());
a = new int[n][n];
b = new int[n][n];
c = new int[n][n];

32. PRIM'S ALGORITHM FOR MST


//PRIM’S ALGORITHM
import java.util.*;
class Prim
{
public static Scanner br =new Scanner(System.in);
static int [][] G;
static int [][] t;
static int [] near;
static int n;
static int mincost = 0;
static int k, l;

31. KRUSKAL ALGORITHM FOR MST


//KRUSKAL ALGORITHM
import java.util.*;
class Kruskal
{
public static Scanner sc =new Scanner(System.in);
static int [][] G;
static int [][] t;
static boolean [][] in;
static boolean [][] temp;
static int n;
static int mincost = 0;
static int k, l, num_ed=0;

30. JOB SEQUENCING WITH DEADLINE


//JOB SEQUENCING WITH DEADLINE
import java.io.*;
import java.util.*;
class jobsequence
{
public static void main(String args[])
{
int m,n,i,j,temp,p,max=0,total_profit=0;
int profit[]=new int[20];
int deadline[]=new int[20];
int sort[]=new int[20];
//int total_profit[]=new int[20];
int lp[]=new int[20];
int up[]=new int[20];
int pos[]=new int[20];
Scanner s=new Scanner(System.in);
System.out.println("Enter the no of Jobs:");
n=s.nextInt();

29. N QUEEN PROBLEM


//N QUEEN PROBLEM
import java.io.*;
public class Queens {
public static boolean isConsistent(int[] q, int n) {
for (int i = 0; i < n; i++) {
if (q[i] == q[n]) return false; // same column
if ((q[i] - q[n]) == (n - i)) return false; // same major diagonal
if ((q[n] - q[i]) == (n - i)) return false; // same minor diagonal
}
return true;
}

28. MULTISTAGE GRAPHS


//MULTISTAGE
import java.io.*;
import java.util.*;
class Multistage
{
public int stages,stage_vertices[],c[][];
public int cost[],p[],n;
public Multistage(int MAX)
{
c=new int[MAX][MAX];
stage_vertices=new int[MAX];
cost=new int[MAX];
p=new int[MAX];
}
public int Get_min(int s,int n)
{
int min=9999;//equal to infinity
int min_vertex=0;

27. KMP PATTERN MATCHING ALGORITHM




//KNUTH-MORRIS PRATT PATTERN MATCHING ALGORITHM
public class KMP {
private final int R;
private int[][] dfa;
private char[] pattern;
private String pat;
public KMP(String pat) {
this.R = 256;
this.pat = pat;
int M = pat.length();
dfa = new int[R][M];
dfa[pat.charAt(0)][0] = 1;
for (int X = 0, j = 1; j < M; j++) {
for (int c = 0; c < R; c++)
dfa[c][j] = dfa[c][X];
dfa[pat.charAt(j)][j] = j+1;
X = dfa[pat.charAt(j)][X];
}
}

26. TRAVELLING SALESPERSON PROBLEM


//TRAVELLING SALESMAN PROBLEM
import java.util.*;
import java.text.*;
class TSP
{
int weight[][],n,tour[],finalCost;
final int INF=1000;
public TSP()
{
Scanner s=new Scanner(System.in);
System.out.println("Enter no. of nodes:=>");
n=s.nextInt();
weight=new int[n][n];
tour=new int[n-1];
for(int i=0;i<n;i++)

25. BANKER'S ALGORITHM


//BANKER’S ALGORITHM
import java.util.*;
class Bankersalgorithm
{
void disp(int m,int n,int alloc[][],int max[][],int avble[],int need[][])
{
char res[]={'A','B','C','D','E','F','G','H','I','J'};
int i,j;
System.out.println("\n\tALLOCATION\tMAX\tNEED\tAVAILABLE");
System.out.println("\n\t\t");
for(i=0;i<4;i++)
{
for(j=0;j<m;j++)
System.out.print(" "+res[j]);
System.out.print("\t\t");
}