Imperative Programming

Traditionally, programming languages use an “imperative” mode, giving action commands to the computer of specific procedures it should enact.

At a low structural level, a “machine language” is used to give very specific instructions to the machine telling it what circuits to open and close. That language is very different from the so-called “natural language” that we use in everyday speech, a higher conceptual-level language with which we would describe a program’s actions verbally. In between those two extreme levels exist one or more other languages that can be typed in by a human, then compiled or interpreted into machine language giving specific instructions to the computer.

When we want to describe a program without reference to any specific programming language, we often explain it in plain natural language or in some mixture of natural language and hypothetical programming language that isn’t strictly correct in any actual programming language. This is often called “pseudo-code”.


“Pseudo-code” for the procedures that will convert Celsius to Fahrenheit

Print “Enter a number of degrees Celsius: “.
Wait until the user types the ‘Enter’ key.
Get whatever was typed up till the ‘Enter’ key, and put it in the memory location named c.
Multiply the value stored in memory location c by 9, then divide the result by 5, then add 32 to that, then store the result in the memory location named f.
Print “That’s equal to “.
Print the value stored in memory location f.
Print ” degrees Fahrenheit.”
Print the ‘Return’ character.


C code for the program ctof.c

#include <stdio.h>

int main( void ){
  float c, f;
  printf( "Enter a number of degrees Celsius: " );
  scanf( "%f", &c);
  f = c*9/5+32;
  printf( "That's equal to %.2f degrees Fahrenheit.\n", f );
  return 0;
}