Sunday, 4 May 2014

Hide Hard disk Drive

---------do your own risk----------

Go to Start >> Run
In run Dialog Box type “diskpart”
>> Enter.
When Diskpart prompt open
Fallow Type fallowing in Diskpart prompt .
1>>list volume
2>>select volume 4 (select volume whatever you want to hide disk)
3>>remove letter D (remove letter whatever you want to hide disk)
4>>Exit
For Assign letter
Same Type 1 & 2. And change “remove” To “assign”
Exit.
For Assign Drive.

Friday, 2 May 2014

Example of Choice in Java

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="Ex63.java" width=500 height=400></applet>*/
public class Ex63 extends Applet
{
  MyChoice choice;
  public void init()
  {
    choice=new MyChoice();
    choice.add("Red");
    choice.add("Green");
    choice.add("Blue");
    add(choice);
  }
  class MyChoice extends Choice
  {
    public MyChoice()
     {
       enableEvents(AWTEvent.ITEM_EVENT_MASK);
     }
    protected void processItemEvent(ItemEvent ie)
    {
         showStatus("Choice selection:"+getSelectedItem());
         super.processItemEvent(ie);
    }
  }

Example Of Jtable

import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;
import java.awt.event.*;

/*<applet code="JTabledemo" width=400 height=200></applet>*/

public class JTabledemo extends JApplet
{


public void init()
{
Container c=getContentPane();



c.setLayout(new BorderLayout());

String[] colHeads={"name","phone no","city"};

Object[][] data={
{"abc","9999999","pune"},
{"xyz","8888888","mumbai"}
};

JTable tb=new JTable(data,colHeads);




int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp=new JScrollPane(tb,v,h);

c.add(jsp,BorderLayout.CENTER);



}


}




Example Of Java Program For JScrollbar (Implement ScrollBar)

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/*<applet code="JScrolldemo" width=200 height=200></applet>*/

public class JScrolldemo extends JApplet
{
public void init()
{

Container c=getContentPane();

c.setLayout(new BorderLayout());

JPanel jp=new JPanel();
jp.setLayout(new GridLayout(2,2));


JRadioButton b1=new JRadioButton("Indian Express");
jp.add(b1);
JRadioButton b2=new JRadioButton("Times of India");
jp.add(b2);
JRadioButton b3=new JRadioButton("Sakal");
jp.add(b3);
JRadioButton b4=new JRadioButton("Lokmat");
jp.add(b4);

ButtonGroup bg1=new ButtonGroup();
ButtonGroup bg2=new ButtonGroup();
bg1.add(b1);
bg1.add(b2);
bg2.add(b3);
bg2.add(b4);

int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp=new JScrollPane(jp,v,h);

c.add(jsp,BorderLayout.CENTER);


}

}

Thursday, 1 May 2014

15 Puzzel problem C Program in C


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

int Game[4][4];

void Reset();
void Left();
void Right();
void Up();
void Down();
void Print();
int  Check();
void Logo();




void main()

{
int counter=0;
 char character='a';
 clrscr();

 Reset();    
 Logo();              
 Print();
 while(character!='q')
 {
  character=getch();
  switch(character)
  {
  case 80:
  Down();
  Print();
  Check();
  break;

  case 77:
  Right();
  Print();
  Check();
  break;

  case 75:
  Left();
  Print();
  Check();
  break;

  case 72:
  Up();
  Print();
  Check();
  break;

  case'r':
  Reset();
  Print();
  Check();
  break;
  }
 }



}


void Logo()
{

 clrscr();

 printf("\n==============================================================================");
 printf("\n                 This GAME Is Designed By ADMIN                ");
 printf("\n==============================================================================");

 printf("\n\n\n\n\n\n\t\t\t Keys: \n\n\n\t\t\t\t Up");
 printf("\n\n\t\t\t\t Down");
 printf("\n\n\t\t\t\t Left");
 printf("\n\n\t\t\t\t Right\n\n\n\n");


 printf("\n\n\n\n\t\t               'q' to Quit.");
 printf("\n\n\n\n\n\n\n\t\t\tPress Any Key To Continue");

getch();
}





void Print()
{       clrscr();

 printf("\n\n\n\n\n\n\n\n\n\n\n\n");
 printf("\n\t\t\t_____________________");
 printf("\n\t\t\t|    |    |    |    |");
 printf("\n\t\t\t|    |    |    |    |");
 gotoxy(27,16);
 {
  printf("%d",Game[0][0]);
 }
 gotoxy(32,16);
 {
  printf("%d",Game[0][1]);
 }
 gotoxy(37,16);
 {
  printf("%d",Game[0][2]);
 }
 gotoxy(42,16);
 {
  printf("%d",Game[0][3]);
 }
 printf("\n\t\t\t|    |    |    |    |");
 printf("\n\t\t\t---------------------");
 printf("\n\t\t\t|    |    |    |    |");
 printf("\n\t\t\t|    |    |    |    |");
 gotoxy(27,20);
 {
  printf("%d",Game[1][0]);
 }
 gotoxy(32,20);
 {
  printf("%d",Game[1][1]);
 }
 gotoxy(37,20);
 {
  printf("%d",Game[1][2]);
 }
 gotoxy(42,20);
 {
  printf("%d",Game[1][3]);
 }
 printf("\n\t\t\t|    |    |    |    |");
 printf("\n\t\t\t---------------------");
 printf("\n\t\t\t|    |    |    |    |");
 printf("\n\t\t\t|    |    |    |    |");
 gotoxy(27,24);
 {
  printf("%d",Game[2][0]);
 } gotoxy(32,24);
 {
  printf("%d",Game[2][1]);
 }
 gotoxy(37,24);
 {
  printf("%d",Game[2][2]);
 }
 gotoxy(42,24);
 {
  printf("%d",Game[2][3]);
 }
 printf("\n\t\t\t|    |    |    |    |");
 printf("\n\t\t\t---------------------");
 printf("\n\t\t\t|    |    |    |    |");
 printf("\n\t\t\t|    |    |    |    |");
 gotoxy(27,28);
 {
  printf("%d",Game[3][0]);
 }
 gotoxy(32,28);
 {
  printf("%d",Game[3][1]);
 }
 gotoxy(37,28);
 {
  printf("%d",Game[3][2]);
 }
 gotoxy(42,28);
 {
  printf("%d",Game[3][3]);
 }
 printf("\n\t\t\t|    |    |    |    |");
 printf("\n\t\t\t~~~~~~~~~~~~~~~~~~~~~");
   
}




void Reset()
{
 int reset=15,i,j;

 for ( i=0;i<4;i++)
 {
  for ( j=0;j<4;j++)
  {
   Game[i][j]=reset--;
  }
 }
 Game[3][3]=0;
}




int Check()
{

    int count=0,i,j,counter;
    int check=0;
    if(check!=0)
    {
    counter++;
    }

 for ( i=0;i<4;i++)
 {
  for ( j=0;j<4;j++)
  {
   count++;
   if(i==3 && j==3)
   {
    break;
   }
   if( Game[i][j]==count)
   {
    check++;
   }

  }
 }
 if(check==15)
 {
  gotoxy(32,36);
  printf("Congratulations");
  return 1;

 }
 else return 0;
}





void Left()
{
 int x,y,i,j;
     
 for ( i=0;i<4;i++)
 {
  for ( j=0;j<4;j++)
  {
   if (Game[i][j]==0)
   {
    x=i;
    y=j;  
   }
  }
 }
 if(y!=3)
 {
  Game[x][y]=Game[x][y+1];
  Game[x][y+1]=0;
 }


}



void Right()
{
 int x,y,i,j;

 for ( i=0;i<4;i++)
 {
  for ( j=0;j<4;j++)
  {
   if (Game[i][j]==0)
   {
    x=i;
    y=j;  
   }
  }
 }
 if(y!=0)
 {
  Game[x][y]=Game[x][y-1];
  Game[x][y-1]=0;
 }


}




void Up()
{
 int x,y,i,j;

 for ( i=0;i<4;i++)
 {
  for ( j=0;j<4;j++)
  {
   if (Game[i][j]==0)
   {
    x=i;
    y=j;  
   }
  }
 }
 if(x!=3)
 {
  Game[x][y]=Game[x+1][y];
  Game[x+1][y]=0;
 }


}





void Down()
{
 int x,y,i,j;

 for ( i=0;i<4;i++)
 {
  for ( j=0;j<4;j++)
  {
   if (Game[i][j]==0)
   {
    x=i;
    y=j;  
   }
  }
 }
 if(x!=0)
 {
  Game[x][y]=Game[x-1][y];
  Game[x-1][y]=0;
 }


}

Longest Common Sub sequence C Propgram

#include<stdio.h>
    #include<string.h>
    #define size 20
    char A[size],B[size];
    int i,j,A_len,B_len;
    int score[size][size];
    void main()
    {
        printf("\tEnter first string\n\t");
        scanf("%s",A);
        printf("\tEnter second string\n\t");
        scanf("%s",B);
        printf("\n");
        A_len = strlen(A);
        B_len = strlen(B);
        A[0] = ' ';
        printf("\t      ");
        for(i=1;i<=B_len;i++)
            printf("%5c",toupper(B[i]));
        printf("\n\n");
        for(i=0;i<=A_len;i++)
        {
            for(j=0;j<=B_len;j++)
            {
                if(i==0 || j==0)
                    score[i][j]=0;
                else if(A[i] == B[j] )
                    score[i][j] = score[i-1][j-1] + 1;
                else
                {
                    if(score[i][j-1]>score[i-1][j])
                        score[i][j] = score[i][j-1];
                    else
                        score[i][j] = score[i-1][j];
                }
            }
        }
        for(i=0;i<=A_len;i++)
        {
            printf("\t%c",toupper(A[i]));
            for(j=0;j<=B_len;j++)
                printf("%5d",score[i][j]);
            printf("\n\n");
        }
        if(score[A_len][B_len] != 0)
        {
            printf("Longest common subsequence is of %d length :\t",score[A_len][B_len]);
        }
        else
            printf("longest common subsequence not found");
       getch();
    }

Bazier curv C program

#include <stdio.h>
#include <graphics.h>
#include <conio.h>
int gd,gm,maxx,maxy;
float xxx[4][2];

/* Function to draw line from relative position
specified in array xxx-----------------------*/

void line1(float x2,float y2)
{
line(xxx[0][0],xxx[0][1],x2,y2);
xxx[0][0]=x2;
xxx[0][1]=y2;
}
/* Bezier function
-------------------- */
void bezier(float xb,float yb,float xc,float yc,float xd,float yd,int n)
{
float xab,yab,xbc,ybc,xcd,ycd;
float xabc,yabc,xbcd,ybcd;
float xabcd,yabcd;
if (n==0)
{
line1(xb,yb);
line1(xc,yc);
line1(xd,yd);
}
else
{
xab = (xxx[0][0]+xb)/2;
yab = (xxx[0][1]+yb)/2;
xbc = (xb+xc)/2;
ybc = (yb+yc)/2;
xcd = (xc+xd)/2;
ycd = (yc+yd)/2;
xabc = (xab+xbc)/2;
yabc = (yab+ybc)/2;
xbcd = (xbc+xcd)/2;
ybcd = (ybc+ycd)/2;
xabcd = (xabc+xbcd)/2;
yabcd = (yabc+ybcd)/2;
n=n-1;
bezier(xab,yab,xabc,yabc,xabcd,yabcd,n);
bezier(xbcd,ybcd,xcd,ycd,xd,yd,n);
}
}

/* Function to initialise graphics
----------------------------------- */
void igraph()
{
detectgraph(&gd,&gm);
if(gd<0)
{
puts("CANNOT DETECT A GRAPHICS CARD");
exit(1);
}
initgraph(&gd,&gm,"d:\\tcpp\\bgi");
}
       void  main()
{
int i;
float temp1,temp2;
igraph();

/* Read two end points and two control points of the curve
---------------------------------------------------------- */
for(i=0;i<4;i++)
{
printf("Enter (x,y) coordinates of point%d : ",i+1);
scanf("%f,%f",&temp1,&temp2);
xxx[i][0] = temp1;
xxx[i][1] = temp2;
}
bezier(xxx[1][0],xxx[1][1],xxx[2][0],xxx[2][1],xxx[3][0],xxx[3][1],8);
getch();
closegraph();
}

Prim Algorithm C Program

/*Prim Algorithm C Program*/
#include<stdio.h>
#include<conio.h>
#define size 20
#define INFINITY 32767
void prim(int G[][size],int nodes)
{
 int tree[size],i,j,k;
 int min_dist,v1,v2,total=0;
 for(i=0;i<nodes;i++)
 {
  tree[i]=0;
 }
  printf("\n\n The minimal spaning tree is:\n");
  tree[0]=1;
  for(k=1;k<=nodes-1;k++)
  {
   min_dist=INFINITY;
   for(i=0;i<=nodes-1;i++)
   {
    for(j=0;j<=nodes-1;j++)
    {
     if(G[i][j]&&((tree[i]&&!tree[j])||(!tree[i]&&tree[j])))
     {
      if(G[i][j]<min_dist)
      {
       min_dist=G[i][j];
       v1=i;
       v2=j;
      }
     }
    }
   }
   printf("\nEdge(%d,%d) and weight=%d",v1,v2,min_dist);
   tree[v1]=tree[v2]=1;
   total=total+min_dist;
  }
  printf("\n\n\tTotal path length is=%d",total);
}
void main()
{
 int G[size][size] ,nodes;
 int v1,v2,length,i,j,n;
 clrscr();
 printf("\n\tPrim's Algorithm\n");
 printf("\nEnter the no. of nodes in Graph");
 scanf("%d",&nodes);
 printf("\nEnter the no. of edges in Graph");
 scanf("%d",&n);
 for(i=0;i<nodes;i++)
  for(j=0;j<nodes;j++)
   G[i][j]=0;
   printf("Enter Edge and weight");
   for(i=0;i<n;i++)
   {
    printf("\nEnter edge by v1&v2:");
    printf("[read the graph from starting node[0]]");
    scanf("%d%d",&v1,&v2);
    printf("Enter the corresponding weight");
    scanf("%d",&length);
    G[v1][v2]=G[v2][v1]=length;
   }
 getch();
 printf("\n\t");
 clrscr();
 prim(G,nodes);
 getch();
}


Queen Problem C Program

/*Queen Problem C Program*/
#include<stdio.h>
#include<conio.h>
void queen(int row,int n);
int place(int row,int column);
int board[20];
void main()
{
int n,row,column;
clrscr();
printf("enter the value of n:");
scanf("%d\n",&n);
queen(row,n);
place(row,column);
getch();
}
void queen(int row, int n)
{
 int column; int board[10];
 for(column=1;column<=n;column++)
    {
     if(place(row,column))
       {
board[row]=column;
if(row==n)
{
printf("%d",board[n]);
}
else
{
queen(row+1,n);
}
       }
    }
}

int place(int row, int column)
{
 int i;
 for(i=1;i<=row-1;i++)
    {
     if(board[i]==column)
       {return 0;}
     else if(abs(board[i]-column)==abs(i-row))
   {return 0;}

    }
    return 1;
}

Kruskal Algorithm C Program

/*Kruskal Algorithm C Program*/

#include<stdio.h>
#include<conio.h>
#define INFINITY 999
typedef struct Graph
{
int v1,v2,cost;
}GR;
GR G[20];
int tot_edges,tot_nodes;
void create();
void spanning_tree();
int Minimum(int);
void main()
{
clrscr();
printf("\n\t\t graph creation by adjacency matrix");
create();
spanning_tree();
getch();
}
void create()
{
int k;
printf("\n enter total no of nodes:");
scanf("%d",&tot_nodes);
printf("\n enter total no of edges:");
scanf("%d",&tot_edges);
for(k=0;k<tot_edges;k++)
{
 printf("\nenter edges in (v1 v2)form:");
 scanf("%d%d",&G[k].v1,&G[k].v2);
 printf("\n enter corresponding cost=");
 scanf("%d",&G[k].cost);
 }
}
void spanning_tree()
{
 int count,k,v1,v2,i,j,tree[10][10],pos,parent[10],sum;
int Find(int v2,int parent[]);
void Union(int i,int j,int parent[]);
 count=0;
 k=0;
 sum=0;
 for(i=0;i<tot_nodes;i++)
   parent[i]=i;
   while(count!=tot_nodes-1)
   {
    pos=Minimum(tot_edges);
    if(pos==-1)
    {
    break;
    }
    v1=G[pos].v1;
    v2=G[pos].v2;
    i=Find(v1,parent);
    j=Find(v2,parent);
    if(i!=j)
    {
      tree[k][0]=v1;
      tree[k][1]=v2;
      k++;
      count++;
      sum+=G[pos].cost;
      Union(i,j,parent);
    }
    G[pos].cost=INFINITY;

 }
   if(count==tot_nodes-1)
   {
    printf("\n spanning tree is:");
    printf("\n-----------------------------\n");
    for(i=0;i<tot_nodes-1;i++)
    {
      printf("[%d",tree[i][0]);
      printf("-");
      printf("%d",tree[i][1]);
      printf("]");
    }
    printf("\n-------------------------------");
    printf("\n cost of spanning tree=%d",sum);
   }
   else
   {
   printf("\n there is no spanning tree");
   }
 }
 int Minimum(int n)
 {
 int i,small,pos;
 small=INFINITY;
 pos=-1;
 for(i=0;i<n;i++)
 {
    if(G[i].cost<small)
    {
    small=G[i].cost;
    pos=i;
    }
 }
 return pos;
 }
 int Find(int v2,int parent[])
 {
 while(parent[v2]!=v2)
 {
   v2=parent[v2];
   }
   return v2;
 }
 void Union(int i,int j,int parent[])
 {
   if(i<j)
   {
     parent[j]=i;
   }
   else
   {
   parent[i]=j;
   }
 }
o/p-

                 graph creation by adjacency matrix
 enter total no of nodes:6

 enter total no of edges:10

enter edges in (v1 v2)form:1
2

 enter corresponding cost=10

enter edges in (v1 v2)form:2
3

 enter corresponding cost=50

enter edges in (v1 v2)form:3
6

 enter corresponding cost=15


enter edges in (v1 v2)form:6 4

 enter corresponding cost=20

enter edges in (v1 v2)form:4 1

 enter corresponding cost=30

enter edges in (v1 v2)form:1 5

 enter corresponding cost=45

enter edges in (v1 v2)form:5 2

 enter corresponding cost=40

enter edges in (v1 v2)form:5 3

 enter corresponding cost=35

enter edges in (v1 v2)form:5 6

 enter corresponding cost=55

enter edges in (v1 v2)form:6 2

 enter corresponding cost=25

 spanning tree is:
-----------------------------
[1-2][3-6][6-4][6-2][5-3]
-------------------------------
 cost of spanning tree=105

OBST C program

       /*  OPTIMAL BINARY SEARCH TREE*/
#include<stdio.h>
#include<conio.h>
#define SIZE 10
void get_data();
int min_value(int i,int j);
void obst();
void build_tree();

int p[SIZE];
int q[SIZE];
int  a[SIZE];
int w[SIZE][SIZE];
int c[SIZE][SIZE];
int r[SIZE][SIZE];
int n;
void get_data()
{
       int i;
       clrscr();
       printf("\n optimal binary search tree\n");
       printf("\n enter no of nodes\n");
       scanf("%d",&n);
       printf("\n enter data as......\n");
       for(i=1;i<=n;i++)
       {
              printf("\n a[%d]",i);
              scanf("%d",&a[i]);
       }
       for(i=1;i<=n;i++)
       {
              printf("\n p[%d]",i);
              scanf("%d",&p[i]);
       }
       for(i=0;i<=n;i++)
       {
              printf("\n q[%d]",i);
              scanf("%d",&q[i]);
       }

}
int min_value(int i,int j)
{
       int m,k;
       int minimum=32000;
       for(m=r[i][j-1];m<=r[i+1][j];m++)
       {
              if(c[i][m-1]+c[m][j]<minimum)
              {
                     minimum=c[i][m-1]+c[m][j];
                     k=m;
              }
       }
       return k;
}
void obst()
{
       int i,j,k,l,m;
       for(i=0;i<n;i++)
       {
              w[i][i]=q[i];
              r[i][i]=c[i][i]=0;
              w[i][i+1]=q[i]+q[i+1]+p[i+1];
              r[i][i+1]=i+1;
              c[i][i+1]=q[i]+q[i+1]+p[i+1];
       }
       w[n][n]=q[n];
       r[n][n]=c[n][n]=0;
       for(m=2;m<=n;m++)
       {
              for(i=0;i<=n-m;i++)
              {
                     j=i+m;
                     w[i][j]=w[i][j-1]+p[j]+q[j];
                     k=min_value(i,j);
                     c[i][j]=w[i][j]+c[i][k-1]+c[k][j];
                     r[i][j]=k;
              }
       }
}
void build_tree()
{
       int i,j,k;
       int queue[20],front=-1; int rear=-1;
       clrscr();
       printf("the optimal binary search tree for the given nodes is....\n");
       printf("\nthe root of this obst::%d",r[0][n]);
       printf("\nthe cost of this obst is::%d",c[0][n]);
       printf("\n\n\tNODE\tLEFT CHILD\tRIGHT CHILD");
       printf("\n----------------------------------------");
       queue[++rear]=0;
       queue[++rear]=n;
       while(front!=rear)
       {

         i=queue[++front];
         j=queue[++front];
         k=r[i][j];
         printf("\n\t%d\t",k);
         if(r[i][k-1]!=0)
         {
            printf("%d\t\t",r[i][k-1]);
            queue[++rear]=i;
            queue[++rear]=k-1;
         }
         else
             printf("-\t\t");
              if(r[k][j]!=0)
              {
                printf("%d\t",r[k][j]);
                queue[++rear]=k;
                queue[++rear]=j;
              }
              else
                  printf("-\t");
            }
            printf("\n");
            }

       void main()
       {
         get_data();
         obst();
         build_tree();
         getch();
         }





/*optimal binary search tree

 enter no of nodes
4

 enter data as......

 a[1]1

 a[2]2

 a[3]3

 a[4]4

 p[1]3

 p[2]3

 p[3]1

 p[4]1

 q[0] 2

 q[1] 3

 q[2] 1

q[3] 1

q[4] 1

the optimal binary search tree for the given nodes is....

the root of this obst::2
the cost of this obst is::32
 NODE    LEFT CHILD      RIGHT CHILD
        --------------------------------------
        2         1                       3
        1         -                        -
        3         -                       4
        4         -                        -

*/

Tennis Tournament C Program

/*Tennis Tournament*/
SOURCE CODE:
#include<stdio.h>
#define SIZE 10
void Schedule(int schedule[SIZE][SIZE],int n);
void Schedule(int Table[SIZE][SIZE],int n)
{
   int days,value,row,col;
   if(n%2)
   value=n+1;
   else
   value=n;
   if(n%2)
   days=n;
 else
   days=n-1;
 for(row=0;row<days;row++)
{
   for(col=0;col<row;col++)
   Table[row][col]=((days+row-col+1)+value)%value;
   for(col=row;col<n;col++)
   Table[row][col]=((days+row-col)+value)%value;
}
row=0;
 for(col=value-2;col>0;col--)
{
   row=((row-2)+days)%days;
   Table[row][0]=Table[row][col];
   Table[row][col]=0;
}
 if(value!=n)
   for(col=0;col<days;col++)
   Table[col][col]=-1;
}
void main(void)
{
   int A[SIZE][SIZE];
   int n,row,col,days;
   clrscr();
   printf("Enter the number of players:");
   scanf("%d",&n);
 if(n%2)
   days=n;
 else
   days=n-1;
   Schedule(A,n);
   printf("\n   Player     ->\n");
   printf("        ");
 for(col=0;col<n;col++)
   printf("%7d",col+1);
   printf("\n");
   printf("Day    |");
   for(col=0;col<7*n;col++)
   printf("-");
  printf("\n");
 for (row=0;row<days;row++)
{
   printf("%7d|",row+1);
 for(col=0;col<n;col++)
   printf("%7d",A[row][col]+1);
   printf("\n");
}
   printf("\n");
   getch();
}
OUTPUT:
Enter the number of players:8

   Player     ->
              1      2      3      4      5      6      7      8
Day    |------------------------------------------------------------
      1|      8      7      6      5      4      3      2      1
      2|      5      8      7      6      1      4      3      2
      3|      2      1      8      7      6      5      4      3
      4|      6      3      2      8      7      1      5      4
      5|      3      4      1      2      8      7      6      5
      6|      7      5      4      3      2      8      1      6
      7|      4      6      5      1      3      2      8      7












All Pair Shortest Path C Program

/*ALL PAIR SHORTEST PATH*/
#include<conio.h>
#include<stdio.h>
void main()
{
   int wt[10][10],n,i,j;
   void Floyd_shortest_path(int matrix[10][10],int n);
   clrscr();
   printf("\n Create a graph using Adjacency Matrix");
   printf("\n\n How many vertices are there ?");
   scanf("%d",&n);
   printf("\nEnter The Elements");
   printf("[Enter 999 as infinity value]");
   for(i=1;i<=n;i++)
   {
    for(j=1;j<=n;j++)
    {
      printf("\nwt[%d][%d]",i,j);
      scanf("%d",&wt[i][j]);
    }
   }
   printf("\n\tComputing All pair shortest path...\n");
   Floyd_shortest_path(wt,n);
   getch();
}
void Floyd_shortest_path(int wt[10][10],int n)
{
   int D[5][10][10],i,j,k;
   int min(int,int);
    for(i=1;i<=n;i++)
   {
    for(j=1;j<=n;j++)
    {
      D[0][i][j]=wt[i][j];
    }
   }
   for(k=1;k<=n;k++)
   {
      for(i=1;i<=n;i++)
     {
       for(j=1;j<=n;j++)
      {
D[k][i][j]=min(D[k-1][i][j],(D[k-1][i][k]+D[k-1][k][j]));
      }
     }
   }
   for(k=1;k<=n;k++)
   {
      printf("\nD(%d)=\n",k);
      for(i=1;i<=n;i++)
     {
      for(j=1;j<=n;j++)
      {
printf("%d\t",D[k][i][j]);
      }
    printf("\n");
   }
  }
}
  int min(int a,int b)
  {
    if(a<b)
    return a;
    else
    return b;
  }
OUTPUT:

 Create a graph using Adjacency Matrix

 How many vertices are there ?4

Enter The Elements[Enter 999 as infinity value]
wt[1][1]0

wt[1][2]999

wt[1][3]3

wt[1][4]999

wt[2][1]2

wt[2][2]0

wt[2][3]999

wt[2][4]999

wt[3][1]999

wt[3][2]7

wt[3][3]0

wt[3][4]1

wt[4][1]6

wt[4][2]999

wt[4][3]999

wt[4][4]0

        Computing All pair shortest path...

D(1)=
0       999     3       999
2       0       5       999
999     7       0       1
6       999     9       0

D(2)=
0       999     3       999
2       0       5       999
9       7       0       1
6       999     9       0

D(3)=
0       10      3       4
2       0       5       6
9       7       0       1
6       16      9       0

D(4)=
0       10      3       4
2       0       5       6
7       7       0       1
6       16      9       0

QUICK SORT C Program

/*QUICK SORT:-C Program created  by Prashant Shinde*/
#include<stdio.h>
#include<conio.h>
int A[10];
void qsort(int,int);
int partition(int,int);
void input(int);
void display(int);
void main()
{
 int n;
 clrscr();
 printf("Enter the no. of element=");
 scanf("%d",&n);
 input(n);
 qsort(0,n-1);
 printf("\nThe sorrted list is:-\n");
 display(n);
 getch();
}
void input(int n)
{
 int i;
 for (i=0;i<n;i++)
 {
  printf("enter a value=");
  scanf("%d",&A[i]);
 }
}
void display(int n)
{
  int i;
 for (i=0;i<n;i++)
 {
  printf("A[%d]=%d\n",i,A[i]);
 }
}
void qsort(int L,int H)
{
  int m;
  if(L<H)
  {
   m=partition(L,H);
   qsort(L,m-1);
   qsort(m+1,H);
  }
}
int partition(int L,int H)
{
 int i=L,j=H,pivote=A[L],t;
 while(i<j)
 {
  while((A[i]<=pivote)&&(i<=H))
  {
   i++;
  }
  while((A[j]>pivote)&&(j>=L))
  {
   j--;
  }
  if(i<j)
  {
   t=A[i];
   A[i]=A[j];
   A[j]=t;
  }
 }
 t=A[L];
 A[L]=A[j];
 A[j]=t;
 return j;
}
OUTPUT:-
Enter the no. of element=7
enter a value=56
enter a value=89
enter a value=23
enter a value=14
enter a value=100
enter a value=159
enter a value=0

The sorrted list is:-
A[0]=0
A[1]=14
A[2]=23
A[3]=56
A[4]=89
A[5]=100
A[6]=159



Merge Sort C Program

                               /*Merge Sort By C Program created By Prashant Shinde*/
MERGE SORT:-
#include<stdio.h>
#include<conio.h>
int A[10];
void msort(int,int);
void combine(int,int,int);
void input(int);
void display(int);
void main()
{
 int n;
 clrscr();
 printf("Enter the no. of element=");
 scanf("%d",&n);
 input(n);
 msort(0,n-1);
 printf("\nThe sortted list is:-\n");
 display(n);
 getch();
}
void input(int n)
{
 int i;
 for (i=0;i<n;i++)
 {
  printf("enter a value=");
  scanf("%d",&A[i]);
 }
}
void display(int n)
{
  int i;
 for (i=0;i<n;i++)
 {
  printf("A[%d]=%d\n",i,A[i]);
 }
}
void msort(int L,int H)
{
  int m;
  if(L<H)
  {
   m=(L+H)/2;
   msort(L,m);
   msort(m+1,H);
   combine(L,m,H);
  }
}
void combine(int L,int m,int H)
{
 int i=L,j=m+1,k=L,t[10];
 while(i<=m&&j<=H)
 {
  if(A[i]<A[j])
  {
   t[k]=A[i];
   i++;
   k++;
  }
  else
  {
   t[k]=A[j];
   j++;
   k++;
  }
 }
 while(i<=m)
 {
   t[k]=A[i];
   i++;
   k++;
 }
  while(j<=H)
 {
   t[k]=A[j];
   j++;
   k++;
 }
 for(k=L;k<=H;k++)
 {
  A[k]=t[k];
 }
}
OUTPUT:-
Enter the no. of element=5
enter a value=789
enter a value=123
enter a value=456
enter a value=258
enter a value=100

The sortted list is:-
A[0]=100
A[1]=123
A[2]=258
A[3]=456
A[4]=789


traveling salesman person problem program in c

/* TRAVELLING SALES PERSON created by prashant shinde*/
#include<conio.h>
#include<stdio.h>
#define MAX 10
typedef struct
{
 int nodes[MAX];
 int vertex;
 int min;
}Path_node;
Path_node TSP(int source ,Path_node list,int Element[][MAX],int max_no_cities)
{
 int i,j;
 Path_node new_list,new_path,new_min;
 if(list.vertex==0)
 {
   new_min.min=Element[source][1];
   new_min.nodes[max_no_cities-1]=source;
   new_min.vertex=max_no_cities;
   return new_min;
 }
 for(i=0;i<list.vertex;i++)
 {
   new_list.vertex=0;
   for(j=0;j<list.vertex;j++)
     if(i!=j)
     new_list.nodes[new_list.vertex++]=list.nodes[j];
     new_path=TSP(list.nodes[i],new_list,Element,max_no_cities);
     new_path.min=Element[source][list.nodes[i]]+new_path.min;
     new_path.nodes[max_no_cities-list.vertex-1]=source;
     if(i==0)
       new_min=new_path;
     else
       if(new_path.min<new_min.min)
 new_min=new_path;
   }
   return new_min;
 }
 void display(Path_node Path)
 {
    int i;
    printf("\n\nThe minimum cost is %d\n",Path.min);
    printf("\n The path is...\n");
    for(i=0;i<Path.vertex;i++)
    printf("%d--",Path.nodes[i]);
    printf("%d",Path.nodes[0]);
 }
 void main()
 {
    int i,j,Element[MAX][MAX],max_no_cities;
    Path_node Graph,Path;
    clrscr();
    printf("\n How many Number of Cities are There?");
    scanf("%d",&max_no_cities);
    if(max_no_cities==0)
    {
       printf("Error:There is no city for processing the TSP");
    }
    else
    {
       for(i=1;i<=max_no_cities;i++)
       {
for(j=1;j<=max_no_cities;j++)
   if(i==j)
      Element[i][j]=0;
   else
   {
     printf("Enter distance from city%d to %d ?",i,j);
     scanf("%d",&Element[i][j]);
   }
   if(i>1)
     Graph.nodes[i-2]=i;
}
Graph.vertex=max_no_cities-1;
Path=TSP(1,Graph,Element,max_no_cities);
display(Path);
     }
     getch();
   }
OUTPUT:

 How many Number of Cities are There?4
Enter distance from city1 to 2 ?2
Enter distance from city1 to 3 ?9
Enter distance from city1 to 4 ?10
Enter distance from city2 to 1 ?1
Enter distance from city2 to 3 ?6
Enter distance from city2 to 4 ?4
Enter distance from city3 to 1 ?15
Enter distance from city3 to 2 ?7
Enter distance from city3 to 4 ?8
Enter distance from city4 to 1 ?6
Enter distance from city4 to 2 ?3
Enter distance from city4 to 3 ?12


The minimum cost is 21

 The path is...
1--3--4--2--1