The purpose of an algorithm

Algorithms are really intended as a blueprint for communication to programmers.

Example: Finding the area of a circle

Problem Definition: A solution is needed to find the area of a circle given a radius.

Solution as a flowchart

Solution in pseudocode:

START 
//variable declaration
float radius
float area
float pi  = 3.14

//input
print "Please enter a radius"
input radius

//processing
area = pi * radius * radius


//output
print "The area is : ", area

END

Actual program code in C:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    float radius, area;
    const float pi = 3.14;
    //input
    printf ("Please enter a radius\n");
    scanf("%f", &radius);

    //processing
    area = pi *radius *radius;
    printf ("\nThe area is : %f", area);



    return 0;
}

Notice how similar the pseudocode is to the actual coded solution.

© 2022  Vedesh Kungebeharry. All rights reserved. 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s