Header Ads Widget

Responsive Advertisement

Basic C-Programming Algorithm part-3 . what is Algorithm? characteristics of Algorithm? what are the benefits of Algorithm? Algorithm - Addition of 3 numbers, Area of Triangle, Largest number between 2 numbers



 What is an Algorithm?

Ans: The method by which a problem is solved step by step is called an algorithm.

Rules and features of the algorithm:

1. The algorithm should be easy to understand.

2. Every step has to be clear.

3. Problem needs to be solved step by step.

The advantage of algorithms:

    1.   Helps to easily understand the purpose of the program.

    2.   Helps diagnose program errors.

    3.   Helps to write complex programs easily.

Example 1: Write an algorithm for finding the sum of 2 numbers.

     Step-1: Start.

Step-2: input 2 number.

Step-3: Adding two numbers.

Step-4: Print the sum.

Step-5: End.

Example 2: Write an algorithm for finding the area of a triangle.

Step-1: Start.

Step-2: Input the land and height of the triangle.

Step-3: Area=1/2*(land*height) use this formula.

Step-4: Print the area.

Step-5: End.

Example 3: Write an algorithm to find the largest number in two integers.

Step-1: Start.

Step-2: Input two numbers.

Step-3: Is the 1st number bigger than the 2nd number?

         1. Yes, print 1st number.

         2. No, print 2nd number.

Step-4: End.

Example 4: Write an algorithm to find the area of a square.

Step-1: Start.

Step-2: Input one square arm.

Step-3: Area = a2

Step-4: Print area.

Step-5: End.

 

 

 

Post a Comment

0 Comments