Sunday, November 6, 2016

Some example of recursion in C programming language

Recursion:

1.     Write a program to find the factorial of number using recursive method.


Source code:
#include<stdio.h>
#include<conio.h>
int factorial(int n)
{
    if(n==0||n==1)
    return 1;
    else
    return n*factorial(n-1);
}
void main()
{        int n,x;
                 printf("Enter the number:");
                 scanf("%d",&n);
                 x=factorial(n);
                  printf("The factorial of %d=%d",n,x);
                  getch();
}

2.     Write a program to multiply two numbers  by recursive method.

Source code:
#include<stdio.h>
#include<conio.h>
int multiplication(int a,int b)
{
    if(b==1)
    return a;
    else
    return a+multiplication(a,b-1);
}
 void main()
 {     int a,b,x;
       clrscr();
       printf("Enter the first number to multiply::");
       scanf("%d",&a);
       printf("Enter the second number to multiply::");
       scanf("%d",&b);
       x=multiplication(a,b);
       printf("%d*%d=%d",a,b,x);
       getch();

 }

3.     Write a program to find the number one exponent to other(ab) using recursion

Source code:
#include<stdio.h>
#include<conio.h>
int power(int a,int b)
{     if(b==0)
      return 1;
      else
      return a*power(a,b-1);
}

void main()
  {   int a,b,x;
      printf("Enter the number a:") ;
      scanf("%d",&a);
      printf("Enter the number b:");
      scanf("%d",&b);
      x=power(a,b);
      printf("%d power %d=%d",a,b,x);
      getch();
  }

4.     Write a program to slove the tower of Hanoi problem using recursion.

Source code:
#include<stdio.h>
#include<conio.h>
void movedisk(int n,char s,char t,char a)
{
if(n==1)
  {
printf("\n move disk from %c to %c",s,t);
return;

  }
movedisk(n-1,s,a,t);
printf("\n move disk from %c to %c",s,t);



movedisk(n-1,a,t,s);
  }
  main()
  {
                  int n;
                  clrscr();
                  printf("How many disk\n:");
                  scanf("%d",&n);
                  movedisk(n,'s','t','a');
                  getch();
                  return 0;
  }



Friday, November 4, 2016

simple user interface using java swing

import javax.swing.*;

import org.omg.CORBA.PRIVATE_MEMBER;

import java.awt.ActiveEvent;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Event;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.geom.Point2D;

public class appframe extends JFrame{

private JLabel item1=new JLabel("Name");
private JLabel item2=new JLabel("Address");
private JTextField name;
private JTextField address;


private JButton okbutton;
private JButton cancelbutton;


private JPanel buttonpanel;
private JPanel textpanel;

public appframe()
{   //setting the title of the app
super("The title v 1.00");

setLayout(new FlowLayout());




//creating the button panel
buttonpanel=new JPanel();

//creating text fields

textpanel=new JPanel();

//creating text field
name=new JTextField(20);
address=new JTextField(25);


//creatin buttons
okbutton=new JButton("OK");
cancelbutton =new JButton("Cancel");
//adding textfield to textpanel
textpanel.add(item1);
textpanel.add(name);
textpanel.add(item2);
textpanel.add(address);




//adding the buttons to buttonpanel
buttonpanel.add(okbutton,BorderLayout.SOUTH);
buttonpanel.add(cancelbutton );
//adding button panel to frame

add(textpanel,BorderLayout.NORTH);
add(buttonpanel,BorderLayout.SOUTH);

thehandler handler = new thehandler();//action listener


okbutton.addActionListener(handler);
cancelbutton.addActionListener(handler);







}
private class thehandler implements ActionListener{


public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub



if(e.getActionCommand()=="OK"){
  buttonpanel.setBackground(Color.blue);

}
if(e.getActionCommand()=="Cancel"){
buttonpanel.setBackground(Color.RED);
}

}
}}



//
create a main method as follows
import javax.swing.JFrame;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;


public class test {

public static void main(String[] args) {
// TODO Auto-generated method stub
 appframe window1=new appframe();
window1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window1.setSize(640,600);


window1.setLocation(100,100);
window1.setVisible(true);
window1.setResizable(false);

}




}



Thursday, November 3, 2016

LISP(list processing)

1.     An overview on lisp(list processing) programming.

Introduction:

 Lisp, an acronym for list processing is a programming language that was designed for easy manipulation of data strings. In lisp all computation is expressed as a function if at least one object. Objects can be other function, data item (such as constants or variables), or data structure. Lisp ability to compute with symbolic expression rather than number makes it convent for AI application.

In, lisp statements are written in prefix notation (e.g. + 2 3). It execute the statement through read-eval-print cycle.

Loop
Read in an expression from the console;
Evaluate the expression;
Print the result of evaluation to the console;

End Loop



Everything in lisp is either an atom or a list. Atom is an operator which determines whether something passed to it is an atom or list. Atom are either constant or variable. List is linearly array of element.

Wednesday, November 2, 2016

what is the difference between the diffuse and specular reflection
Diffuse reflection Specular reflection
1. reflection in the rough surface produce 1. reflection in the shiny surface produce
2. viewing direction doesn't affect 2. viewing direction affect the intensity of light reflected

Tuesday, November 1, 2016

8085 microprocessor assembly programming language

Microprocessor is a electronic chip, that functions as the central processing unit of a              computer.
For example: Washing machines, microwave ovens, mobile phones etc.
Its advance applications are Radar, Satellites, flights.
All processors are use the basic concept of stored program execution. program or instructions are stored sequentially in the memory. Every microprocessor has its own associated set of instructions. Instruction set for microprocessor is in two forms one in mnemonic, which is comparatively easy to understand and the other is binary machine code.


1. arithmatic and logic unit :
The ALU performs the actual numerical and logic operation such as add’, ‘subtract’, ‘AND’, ‘OR’, etc. Uses data from memory and from Accumulator to perform arithmetic. Always stores result of operation in Accumulator.
2. genaral purpose registers:
8-bit B and 8-bit C registers can be used as one 16-bit BC register pair. When used as a pair the C register contains low-order byte. Some instructions may use BC register as a data pointer.
8-bit D and 8-bit E registers can be used as one 16-bit DE register pair. When used as a pair the E register contains low-order byte. Some instructions may use DE register as a data pointer.
8-bit H and 8-bit L registers can be used as one 16-bit HL register pair. When used as a pair the L register contains low-order byte. HL register usually contains a data pointer used to reference memory addresses.
3.   special purpose registers:
a) Accumulator or A register is an 8-bit register used for arithmetic, logic, I/O and load/store operations.
b) Flag is an 8-bit register containing 5 1-bit flags:
  • Sign - set if the most significant bit of the result is set.
  • Zero - set if the result is zero.
  • Auxiliary carry - set if there was a carry out from bit 3 to bit 4 of the result.
  • Parity - set if the parity (the number of set bits in the result) is even.
  • Carry - set if there was a carry during addition, or borrow during subtraction/comparison.
c)Stack pointer is a 16 bit register. This register is always incremented/decremented by 2
d)Program counter is a 16-bit register.
 4. instruction register and decoder:
Temporary store for the current instruction ofa program. Latest instruction sent here from memory prior to execution. Decoder then takes instruction and ‘decodes’ or interprets the instruction. Decoded instruction then passed to next stage.
5. Timing and control unit: Generates signals within uP to carry out the instruction, which has been decoded. In reality causes certain connections between blocks of the uP to be opened or closed, so that data goes where it is required, and so that ALU operations occur.


For assembly language  program click here







c programs

View blog cslearning · Page c programs Update Revert to draft Preview Close ComposeHTML Link
There are some c programs for data structure
CONTENTS

Stack
1. Write a program in c to implement the stack using array . 2
2. Write a program in c to implement the stack using structure. 5
3. Write a C program to evaluate the postfix expression. 9
4. Write a program to convert an infix expression into postfix expression. 12
5. Write a program to convert infix expression into prefix expression. 15
Recursion: 19
6. Write a program to find the factorial of number using recursive method. 19
7. Write a program to multiply two numbers by recursive method. 20
8. Write a program to find the number one exponent to other(ab) using recursion 20
9. Write a program to slove the tower of Hanoi problem using recursion. 21
Queue 22
10. Write a program in C to implement the queue using structure. 22
11. Write a program in C to implement the queue using array. 26
Circular queue 30
12. Write a program in C to implement the circular queue. 30
13. Write a program to implement the ascending order priority queue. 34
Contiguous list 34
14. Write a program to implement the contiguous linked list. 34
15. Write a program to show implementation of linked list. 37
16. Write a program to show linked implementation of stack. 43
17. Write a program to show the linked implementation of queue. 47
Searching 52
18. Write a program to sequential search the item. 52
19. Write a program to implement the binary search. 53
Tree 54
20. Write a program to implement the binary tree. 54
Sorting 59
21. Write a program to sort the item using selection sort. 59
22. Write a program to sort the item using bubble sort. 61
23. Write a program to sort the item using quick sort. 62
24. Write a program to sort the item using merge sort. 64
25. Write a program to sort the item using insertion sort. 67
26. Write a program to sort an item using heap sort. 68

click here
This is my first blog post.

Socket Programming in Java

Source Code: client Side: package learning; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event....