Saturday, December 17, 2011

C Program for Binary Search....

/* binary Search*/

#include<conio.h>
#include<stdio.h>
int main()
{
  int a[10],i,n,m,c=0,l,u,mid;

  printf("Enter the size of an array->");
  scanf("%d",&n);

  printf("\nEnter the elements of the array in sorted order->");
  for(i=0;i<n;i++)
      scanf("%d",&a[i]);
 
  printf("\nThe elements of an array are->");
  for(i=0;i<n;i++)
      printf(" %d",a[i]);
 
  printf("\nEnter the number to be search->");
  scanf("%d",&m);
 
l=0,u=n-1;

  while(l<=u)
    {
      mid=(l+u)/2;
      if(m==a[mid])
    {
          c=1;
              break;
          }
      else if(m<a[mid])
    {
              u=mid-1;
        }
      else
          l=mid+1;
   }

  if(c==0)
      printf("\nThe number is not in the list");
  else
      printf("\nThe number is found at %d",mid+1);
  getch();
}

C Program for Sum of Matrix .......

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[3][3],b[3][3],c[3][3],i,j,k,sum=0;
 clrscr();
 printf("Enter the element of 1st 3*3 matrix:");
  for(i=0;i<3;i++)
     for(j=0;j<3;j++)
    scanf("%d",&a[i][j]);

 printf("Enter the element of 2nd 3*3 matrix:");
  for(i=0;i<3;i++)
     for(j=0;j<3;j++)
    scanf("%d",&b[i][j]);

  for(i=0;i<3;i++)
    {   
     for(j=0;j<3;j++)
    {
         c[i][j]=a[i][j]+b[i][j];
    }
     }   


printf("\n1st Matrix is :\n");
  for(i=0;i<3;i++)
   {   
     for(j=0;j<3;j++)
      {
    printf("\t%d",a[i][j]);
      }
    printf("\n");
    }

printf("\n2nd Matrix is :\n");
  for(i=0;i<3;i++)
   {   
     for(j=0;j<3;j++)
      {
    printf("\t%d",b[i][j]);
      }
    printf("\n");
    }
printf("\nOutput Matrix is :\n");
  for(i=0;i<3;i++)
   {   
     for(j=0;j<3;j++)
      {
    printf("\t%d",c[i][j]);
      }
    printf("\n");
    }
getch();

}

C program for find the minimum and maximum value in an array...

/* find the min and max value with these locations*/
#include<stdio.h>
#include<conio.h>
void main()
{
 int a[20],i, n,max,min,min_pos,max_pos;
 clrscr();
 printf("Enter the Limit:");
 scanf("%d",&n);

 if(n<=20)
    {
        printf("Enter The No for Array:");
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
   
        max=a[0];
        min=a[0];
        for(i=0;i<n;i++)
            {
                if(a[i]>=max)
                    {
                        max=a[i];
                        max_pos=i+1;
                    }
                if(a[i]<=min)
                    {
                        min=a[i];
                        min_pos=i+1;
                    }

            }   
        printf("\nThe Bigest number in array is %d at %d",max,max_pos);
        printf("\nThe Smallest number in array is %d at %d",min,mix_pos);
       
    }
   else
    printf("Enter the value of less than or equal to 20");

 getch();
       
}

C Program for find the Greatest Number in an array...

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[20],i, n,max;
 clrscr();
 printf("Enter the Limit:");
 scanf("%d",&n);

 if(n<=20)
    {
        printf("Enter The No for Array:");
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
   
        max=a[0];
        for(i=0;i<n;i++)
            {
                if(a[i]>=max)
                    max=a[i];
            }   
        printf("\nThe Bigest number in array is %d",max);
       
    }
   else
    printf("Enter the value of less than or equal to 20");

 getch();
       
}

Wednesday, November 30, 2011

program of Calculator in java


/**********************Calculator in java AWT******************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Calculator implements ActionListener,WindowListener
{

        String data= "0",opr;
  int number, first_number, result;

       
 Frame f;
 Button b[]=new Button [10];
 Button b1[]= new Button [6];

 TextField tf;
 
 Calculator()
 {
   f= new Frame("Calculator");
   tf= new TextField("");

   for(int i=0;i<10;i++)
    {
  String str= Integer.toString(i);
b[i]= new Button(str);
     }
 
   b1[0]= new Button("+");
   b1[1]= new Button("-");
   b1[2]= new Button("*");
   b1[3]= new Button("/");
   b1[4]= new Button("C");
   b1[5]= new Button("=");

 
 }

 void display()
 {

  try{
  int left,top, hight,width;
   left=20;
   top=80;
   hight=30;
   width=30;

 f.setLayout(null);
//  f.setSize(220,250);
 f.setBounds(350,250,220,250);
  f.setVisible(true);



  for(int i=1;i<10;i++)
{
     
      b[i].setBounds(left,top,width,hight);

if(i%3==0)
{
top=top+40;
left= 20;
}
       
else
left=left+40;
             
    }


b[0].setBounds(left+40,top,width,hight);
   
b1[0].setBounds(left+120,80,width*2,hight);
b1[1].setBounds(left+120,120,width*2,hight);
b1[2].setBounds(left+120,160,width*2,hight);
b1[3].setBounds(left+120,200,width*2,hight);
b1[4].setBounds(left,200,width,hight);
b1[5].setBounds(left+80,200,width,hight);


tf.setBounds(left,40,180,hight);

for(int i=0;i<10;i++)
  f.add(b[i]);

for(int i=0;i<6;i++)
  f.add(b1[i]);


f.add(tf);


for(int i=0;i<10;i++)
b[i].addActionListener(this);

for(int i=0;i<6;i++)
b1[i].addActionListener(this);
f.addWindowListener(this);
  }
 catch(Exception e)
{
System.out.println(e);
}
 }


/**************************************Window Listener Interface************************/

public void windowActivated(WindowEvent e)
{}
public void windowClosed(WindowEvent e)
{}
public void windowClosing(WindowEvent e)
{

System.exit(1);

}
public void windowDeactivated(WindowEvent e)
{}
public void windowDeiconified(WindowEvent e)
{}
public void windowIconified(WindowEvent e)
{}
public void windowOpened(WindowEvent e)
{}





public void actionPerformed(ActionEvent e)
{


try{

if(e.getSource()==b[0])        
{
number=(number*10)+0;
data=Integer.toString(number);
tf.setText(data);

}
else if(e.getSource()==b[1])        
{
number=(number*10)+1;
data=Integer.toString(number);
tf.setText(data);

}
else if(e.getSource()==b[2])        
{
number=(number*10)+2;
data=Integer.toString(number);
tf.setText(data);

}

else if(e.getSource()==b[3])        
{
number=(number*10)+3;
data=Integer.toString(number);
tf.setText(data);

}

else if(e.getSource()==b[4])        
{
number=(number*10)+4;
data=Integer.toString(number);
tf.setText(data);

}

else if(e.getSource()==b[5])        
{
number=(number*10)+5;
data=Integer.toString(number);
tf.setText(data);

}

else if(e.getSource()==b[6])        
{
number=(number*10)+6;
data=Integer.toString(number);
tf.setText(data);

}
else if(e.getSource()==b[7])        
{
number=(number*10)+7;
data=Integer.toString(number);
tf.setText(data);

}
else if(e.getSource()==b[8])        
{
number=(number*10)+8;
data=Integer.toString(number);
tf.setText(data);

}

else if(e.getSource()==b[9])        
{
number=(number*10)+9;
data=Integer.toString(number);
tf.setText(data);

}
else if(e.getSource()==b1[4])
{

}


/**************************************************************************/
if(e.getSource()==b1[0])
{
opr="+";
first_number=number;
number=0;
}
else if(e.getSource()==b1[1])
{
opr="-";
first_number=number;
number=0;
}
else if(e.getSource()==b1[2])
{
opr="*";
first_number=number;
number=0;
}
else if(e.getSource()==b1[3])
{
opr="/";
first_number=number;
number=0;
}
else if(e.getSource()==b1[4])
{
opr=" ";
number=0;
first_number=0;
result=0;
tf.setText(" ");
}
else if(e.getSource()==b1[5])
{
if(opr.equals("+"))
{
result=number+first_number;
data=Integer.toString(result);
tf.setText(data);
number=result;
result=first_number;
}

else if(opr.equals("-"))
{
result=number-first_number;
data=Integer.toString(result);
tf.setText(data);
number=result;
result=first_number;
}
else if(opr.equals("*"))
{
result=number*first_number;
data=Integer.toString(result);
tf.setText(data);
number=result;
result=first_number;
}

else if(opr.equals("/"))
{
result=number+first_number;
data=Integer.toString(result);
tf.setText(data);
first_number=result;
result=number;
}
}


   }
catch(Exception ex)
{
System.out.println(ex);
}

}


}

//****************************************************************************

class CalculatorTest
{
 public static void main(String args[])
 {
 Calculator c= new Calculator();
 c.display();
 }
}

/***************************Pic of Calculator*****************************************/


/******************Download the Zip file of above program********************************/
Download the Zip file of Calculator


Thursday, November 24, 2011

few Fun Movements.....

enjoy the Life Cycle of Love heeee heee


Paint brush program in java Applet

hi ...
this is a applet class of Paint brush...
u can download it .......
**************************snap shot of running program*********************************

you can download the zip file of above program
Download the zip file of Paint Brush