请输入您要查询的字词:

 

单词 C1
释义

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 languagePlanetmathPlanetmath; 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 divisorMathworldPlanetmath using Euclid’s algorithmMathworldPlanetmath.

#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 -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.

References

  • 1 M. Banahan, D. Brady & M. Doran, The C book, featuring the ANSI C standard Reading, Mass: Addison-Wesley Publishing (1991)
随便看

 

数学辞典收录了18232条数学词条,基本涵盖了常用数学知识及数学英语单词词组的翻译及用法,是数学学习的有利工具。

 

Copyright © 2000-2023 Newdu.com.com All Rights Reserved
更新时间:2025/5/4 11:25:57