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.
Demo: 1. Visit Scratch.mit.edu or open scratch version 3 2. Add the pen addon to the scratch project 3. Experiment with the blocks that use the pen 4. Draw a square of side 50 units
Task: Prompt the user to enter a value and store it in a variable called “Side”. Proceed to draw a square with a length of side equal to “Side”. (Assume the user enters a size that can fit in the stage area.)