Ensemble Home
Login
Search
About
Contact
Ensemble Collections
Collections Home
->
Planet Math Collection
-> C
TITLE
C
SUBJECT
msc:68N15
SUBJECT
mathematics
DESCRIPTION
... 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 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; printf("Please enter x "); inputSuccess = scanf("%d", &inputX); printf("Please enter y "); inputSuccess = scanf("%d", &inputY); printf("GCD of %d and %d is %d ... ", inputX, inputY, GCD(inputX,inputY)); exit(EXIT_SUCCESS); } ... 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 ... , 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. ...
PUBLISHER
PlanetMath
DATE
2008-04-04
TYPE
text
FORMAT
text/html
IDENTIFIER
planetmath:179
SOURCE
http://planetmath.org/encyclopedia/CProgrammingLanguage.html
LANGUAGE
en-us
Powered by
Drupal
, an open source content management system.
Arch images by
criminalintent
,
auntlaura
, and
geishaboy500
.
CC BY-SA 2.0