This Blog is on latest technologies,some quick fix and different prototypes they haven't even launched yet to show show u how much the world have progressed

Sunday, 1 November 2015

lecture # 5 : building logic through presudo code

before proceeding let me tell you some hard facts about computer

algorithm aren't computer codes so your style to demonstrate yor logic
computer deals with finite things
which means whole numbers and numbers never lie

computer is a device that takes input process it and gives out-come

outcome must be desired one (required one)

now we would see some algorihms

Write an algorithm to add two numbers entered by user.

Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
        sum←num1+num2
Step 5: Display sum
Step 6: Stop

Write an algorithm to find the largest among three different numbers entered by user.

Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a>b
           If a>c
              Display a is the largest number.
           Else
              Display c is the largest number.
        Else
           If b>c
              Display b is the largest number.
           Else
              Display c is the greatest number. 
Step 5: Stop

Write an algorithm to find all roots of a quadratic equation ax2+bx+c=0.

Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and ip;
Step 3: Calculate discriminant
         D←b2-4ac
Step 4: If D≥0
              r1←(-b+√D)/2a
              r2←(-b-√D)/2a
              Display r1 and r2 as roots.
        Else    
              Calculate real part and imaginary part
              rp←b/2a
              ip←√(-D)/2a
              Display rp+j(ip) and rp-j(ip) as roots
Step 5: Stop      
      
Write an algorithm to find the factorial of a number entered by user.

Step 1: Start
Step 2: Declare variables n,factorial and i.
Step 3: Initialize variables
          factorial←1
          i←1
Step 4: Read value of n
Step 5: Repeat the steps until i=n
     5.1: factorial←factorial*i
     5.2: i←i+1
Step 6: Display factorial
Step 7: Stop

Write an algorithm to check whether a number entered by user is prime or not.

Step 1: Start
Step 2: Declare variables n,i,flag.
Step 3: Initialize variables
        flag←1
        i←2 
Step 4: Read n from user.
Step 5: Repeat the steps until i<(n/2)
     5.1 If remainder of n÷i equals 0
            flag←0
            Go to step 6
     5.2 i←i+1
Step 6: If flag=0
           Display n is not prime
        else
           Display n is prime
Step 7: Stop


Write an algorithm to find the Fibonacci series till term≤1000.

Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term←0 second_term←1
Step 4: Display first_term and second_term
Step 5: Repeat the steps until second_term≤1000
     5.1: temp←second_term
     5.2: second_term←second_term+first term
     5.3: first_term←temp
     5.4: Display second_term

Step 6: Stop




Share:

lesson # 4 : intro to algorithm

here we will see what is algorithms

algorithms are refined presudo codes

means algorithms are presudo codes which are filtered in such a way that they could be easily read and are shorted

presudo code  ( show the value of x after adding 2 to it )

1) let a varaible x
2) x has initial value 0
3) in x add 2 to x
3) show value of x

algorithm  

1) let x=0
2) x+2
3 show x

how its a refined form of presudo code

now in next lecture we will practice some logic building skill with algorithm 
Share:

lecture #3 :intro presudo code

now to learn a programming language you must need to learn 2 thing to achieve the third

1) presudo codes   (logic building)
2) flow charts        (showing your logic graphically)
3) programming language   (practically implementing your logic)

so presudo codes means the instruction to acheive a given task in a logical manner....

for example
someone asks you to make him a tea

so your presudo code (instruction) for the tea making would be

1. put water in kettle
2. boil it
3. drop your tea bag in boiled water
4. add some milk
5. tea is ready

so a tea could me made in 5 simple steps ...well of coarse you can expand the steps and reduce them

expanding it would make its easy to read
reducing it would make it tougher to read

so we would take our presudo codes to the very next level in your next lesson
Share:

lesson # 2 : logic building

this is where your actual learning begins

before trying to learn any programming language first learn how to use it
like you learn English but you don't know how to do a conversation ...its of no use

so to learn a programming language first you need to learn the skill known as logic building

like  2 + 2 = 4

whats logic in it...??

a)2= 1 &1
b)so 2+2 means  1&1&1&1 
c)which makes it 4

see how i give a logical meaning to math equation

its called divide and conquer method..

def : for a big thing you divide it into tiny compartments and solve each individual ones

this method is going to be used in our next lec
Share:

lecture #1 : intro to programming

well most of the time programmers thinks that this is the best they could do , stopping at a point ,breaking point , to me a person who surpass that breaking point deserves to be a real programmer. rest will be just a bunch of peeps who knows how to code ...

so lesson #1

if you really are into programming then prove it by investing your time . even if you fail try,try again and at some point you will suceed..:D
cause at the point where you think its out of your league that is where the actual learning begins
Share: