# C

C is a procedural compiled programming language devised by Dennis Ritchie at the Bell Labs in New Jersey in 1972, and standardized in 1983 by ANSI and again by ISO in 1999. The original purpose of C was to write systems software for UNIX, but soon it became the most popular programming language for writing DOS applications, a popularity overshadowed only by the success of using C++ (http://planetmath.org/C) for Windows applications. From the beginning C provided access to certain lower level features of the computer and if that’s not enough it also had simpler mechanisms for meshing with assembly language; for that reason C is sometimes compared to dangerous but powerful tools like a chainsaw (Banahan et al, 1991).

The following C program takes two integers as inputs and outputs their greatest common divisor using Euclid’s algorithm.

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

int GCD(int x, int y) {
int wX = x;
int wY = y;
int tempX;
while ( wY > 0 ) {
tempX = wX;
wX = wY;
wY = tempX % wY;
}
return(wX);
}

int main() {
int inputX;
int inputY;
int inputSuccess;
inputSuccess = scanf("%d", &inputX);

This program was tested in Visual C++ 6.0, and it works. The compiler reported 0 errors and 0 warnings, and the program works as it should, at least as long as the inputs are both positive integers. For the pair 42 and $-21$, it incorrectly reports the GCD as 42. Note that printf is not a reserved word of the C language, the way that PRINT is in BASIC or Fortran. We can use it because we included the standard I/O library; theoretically, we could write our own printf that tye-dyed the output onto a T-shirt as long as we wrote the appropriate library to take care of it.