Sunday, November 3, 2013

Calculate Cube Root using JAVA

import java.util.*; //Packeage required to use Scanner class
class Root
{
public static void main(String x[])
{
Scanner sc=new Scanner(System.in);//To accept inputs using Scanner reference
System.out.println("Enter number"); // To display the message
double n=sc.nextDouble(); // Accept the user input in 'double' data type and
                         // and store it in variable 'n'

System.out.println("Cube root of "+n+" is "+Math.pow(n,1.0/3)); // Calculate cube root and                                                                                                                           //display it

}
}
OUTPUT



I tried to keep this program as simple as I could. However if you have still any questions , suggestions , feedback or any other thing , feel free to comment in the comment section below.
I'll be very glad to hear from you about this blog.
Happy Programming!!!!


Friday, October 25, 2013

Debug Program d=a+b-c


Debug program for d=a+b-c



Here are the steps to be executed

1. First open 'Debug' terminal. If you are using Windows OS 32 bit, go through following steps
    Way 1:
     a. Open start menu.
     b. type debug in the search box.
     c. And finally hit enter to open 'debug' terminal.

    









Way 2:
     a. Open command prompt.
          It can easily be done by typing cmd (without quotes) in the search area or run area(in Windows XP)
    b. Type debug and hit enter.









    Program Algorithm and implementation:
1. First we will have to store the input which we will be giving in the program.
     It can be simply done by using e command which stands for 'edit'.
     SO we just type:
     e 1000
     It means that we want to edit memory location 1000
     Now we will need three inputs. One for 'a', one for 'b', and other one for 'c'
     So for this we will be using memory locations 1001 , 1002 and 1003 respectively.

2.But before that we will need some memory locations
where we can store our instructions.
We will be storing our instructions at location 2000
To accomplish this we type following:
a 2000
 
2. First we will copy the content of memory location 1000 to AL register.
     Hence we write
     mov al,[1000]
3. Then we will copy content of  of memory location 1001 to BL register.
     Hence we write
     mov bl,[1000]
4. Now we will add the values stored in al and bl and store the result in AL register.
It can be simply done by following instruction.
add al,bl


Here add accepts two values as follows

add destination, source


Here content   of source and destination locations are added and the result is stored in destination itself.



5. Now we will subtract the result with the content of memory location 1002.

It can be simply done by following instruction.
sub al,[1002]


Here sub accepts two values as follows

sub destination, source


Here content   of source is subtracted with content of destination and the result is stored in destination itself.



6. Now as we have stored the result in al register we will copy it to memory location 1003 where we want to keep our output.

It can be simply done by following instruction.
mov [1003] ,al

7. Now because we have stored our result at desired place we will now halt.
It can be done by following instruction.
hlt


8. Now its time to execute the code that we have typed so far.

We started typing our instructions from memory location 2000 and ended at location 2011
So we type following command

g=2000 2011

Here g stands for 'GO'.



So finally we have successfully executed our first program.

Now its time to check the output.

CHECK OUTPUT


1. Remember we stored our output at memory location 1003
    So type following to check content of 1003 and 1004
    We will ignore the content of 1004
     
     d 1003 1004
     Check it out.
     We will have our output in memory location 1003.

In this sample example I stored 4,3,2 respectively.
And we can clearly see 5 stored at memory location 1003.


I tried to keep this tutorial as simple as I could. However if you have still any questions , suggestions , feedback or any other thing , feel free to comment in the comment section below.
I'll be very glad to hear from you about this blog.
Happy Programming!!!!