Algorithm - Key To Successful Programming

          -------------        Key To Programming     ---------------


LEARNERS FIND HARD FOR THEMSELVES TO ADAPT TO ANY PROGRAMMING LANGUAGE AND THEY BLAME It, EITHER THEMSELVES OR THAT THE LANGUAGE IS NOT QUITE SATISFYING.

  THE HIDDEN KEY BEHIND IT  ----- Algorithm.      

Defination:-
Algorithms - A Key To Coding


Algorithm( Al -go-rith-um) can be defined as a procedural & well-defined sequence or flow of steps leading to an expected result or output.
     
     ---->    To understand an algorithm, let's understand 3 simple steps for a computer to perform work.
   Input -- Processing --Output.

Such that.
Step1: - Input (Computer is a dumb machine which requires instructions)
Step 2: Processing (Without instruction a Computer will be idle, it needs task)
Step 3:- Output( only if input and processing is done it will produce an output)

 Example 2:- 
                          A more precise example is "BUYING THINGS FROM STORE", We first go to vendor(online/ offline) , select the goods to buy and ask shopkeeper(Compiler/ in programming terms) i:e provide him with apt and unambiguous instructions which help him to understand us and hence help us out(Output).

So,
     An  Algorithm should have following characteristics --

1.Inputs and outputs should be precise.
2. Unambiguous (not confusing and straight to point).
3. Most effective (i:e it can perform operations depending on range of  inputs)
4.Never is a programming code. (it's similar to programming language).

NOTE:-
An Algorithm can be expressed in terms of  any language, ranging from English, French till FORTRAN.  


Example To Algorithm


Examples Of Algorithm in Programming :-

1. Algorithm to add two numbers :-

   Step 1 :- Create 3 variable num1,num2,sum 
   Step 2 :- Read Values num1 and num2
   Step 3 :- Add num1 & num2 and store it in sum
   Step 4 :- Print Add .

2. Algorithm to Subtract two numbers :-

  Step 1:- Create 3 variables num1, num2 and subtract
  Step 2 :- Read  Values num1 and num2
 Step 3:- if a>b
                  then
                         assign subtract with a-b

else 
                        assign subtract with b-a
Step 4:- Print Subtract

3. Algorithm To divide two numbers :-

Step 1 :- Create 3 variables num1, num2 , divide
Step 2 :- Read Values for num1 & num 2
Step 3 :- If  (a  && b ! = 0)
                       then
                 if (a>b)
                        then
                               assign a/b to divide 
Print divide
              else
                        assign divide with b/a
Print divide
             else
                  Print "Wrong Input "

4. Algorithm to Multiply Two Numbers : -

Step 1 :- Create 3 variables num1,num2, and Multiply .
Step 2 : - Read Value for num1 & num2
Step 3 :- assign multiply with num1*num2
Step 4 :- Print Multiply

5. Algorithm to find factorial :-

Step 1 :- Create two variables fact, num , counter
Step 2 : - initialize default values to 
                 fact=1
                 counter =1
Step 3 : - Read Value of n
Step 4 : -  while(counter !=fact
                 fact=fact*counter
               Repeat until counter == fact
Step 5 : - Print fact

Note:- Read Value (User Input using scanf(), or whatever function to take user input)
        
Above are some of the Examples related to Algorithms, it might have made your concept regarding some easy yet tricky programming related divide and factorial easy.
      

         Try it out.

  1. Algorithm to check if the number is Prime or Not
  2. Algorithm to check even or odd
  3. Algorithm to print fibonacci Series.
  4. Algorithm to calculate sum of natural numbers 
  5. Algorithm to find Quadratic Roots.

Thanks to Hazz Law for asking me to post something relevant. (keep asking and we sure will respect it.

          Hope you wanna know more related terms and ease to programming ways.

Comments

Popular posts from this blog

Introduction To Pointers

Introduction To C