⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 programs.shar

📁 The art and science of c_source code!
💻 SHAR
📖 第 1 页 / 共 5 页
字号:
# end of 'programs/03-Problem-Solving/roses.c'fiif test -f 'programs/04-Statement-Forms/Makefile' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'programs/04-Statement-Forms/Makefile'\"elseecho shar: Extracting \"'programs/04-Statement-Forms/Makefile'\" \(1906 characters\)sed "s/^X//" >'programs/04-Statement-Forms/Makefile' <<'END_OF_FILE'X# Makefile for cbook/04-Statement-Forms/programsX# Created by the ExportAll facilityX# ***************************************************************XXPROGRAMS = \X    leapyear \X    oddeven \X    signtest \X    cardrank \X    digitsum \X    addlist \X    liftoff \X    timestab XX# ***************************************************************X# Parameters to control Makefile operationX# Note that the gccx command script must be definedXXCC = gccxXCFLAGS = XX# ***************************************************************X# Entry to bring the package up to dateXXall: $(PROGRAMS)XX# ***************************************************************X# Standard entries to remove files from the directoriesX#    tidy    -- eliminate unwanted filesX#    scratch -- delete derived files in preparation for rebuildXXtidy:X	rm -f ,* .,* *~ core a.out graphics.psXXscratch: tidyX	rm -f *.o *.a $(PROGRAMS)XX# ***************************************************************X# C compilationsXXleapyear.o: leapyear.cX	$(CC) $(CFLAGS) -c leapyear.cXXoddeven.o: oddeven.cX	$(CC) $(CFLAGS) -c oddeven.cXXsigntest.o: signtest.cX	$(CC) $(CFLAGS) -c signtest.cXXcardrank.o: cardrank.cX	$(CC) $(CFLAGS) -c cardrank.cXXdigitsum.o: digitsum.cX	$(CC) $(CFLAGS) -c digitsum.cXXaddlist.o: addlist.cX	$(CC) $(CFLAGS) -c addlist.cXXliftoff.o: liftoff.cX	$(CC) $(CFLAGS) -c liftoff.cXXtimestab.o: timestab.cX	$(CC) $(CFLAGS) -c timestab.cXXXleapyear: leapyear.oX	$(CC) $(CFLAGS) -o leapyear leapyear.oXXoddeven: oddeven.oX	$(CC) $(CFLAGS) -o oddeven oddeven.oXXsigntest: signtest.oX	$(CC) $(CFLAGS) -o signtest signtest.oXXcardrank: cardrank.oX	$(CC) $(CFLAGS) -o cardrank cardrank.oXXdigitsum: digitsum.oX	$(CC) $(CFLAGS) -o digitsum digitsum.oXXaddlist: addlist.oX	$(CC) $(CFLAGS) -o addlist addlist.oXXliftoff: liftoff.oX	$(CC) $(CFLAGS) -o liftoff liftoff.oXXtimestab: timestab.oX	$(CC) $(CFLAGS) -o timestab timestab.oEND_OF_FILEif test 1906 -ne `wc -c <'programs/04-Statement-Forms/Makefile'`; then    echo shar: \"'programs/04-Statement-Forms/Makefile'\" unpacked with wrong size!fi# end of 'programs/04-Statement-Forms/Makefile'fiif test -f 'programs/04-Statement-Forms/addlist.c' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'programs/04-Statement-Forms/addlist.c'\"elseecho shar: Extracting \"'programs/04-Statement-Forms/addlist.c'\" \(689 characters\)sed "s/^X//" >'programs/04-Statement-Forms/addlist.c' <<'END_OF_FILE'X/*X * File: addlist.cX * ---------------X * This program adds a list of numbers.  The end of theX * input is indicated by entering 0 as a sentinel value.X * This version of the implementation uses a while loopX * without a break statement, which forces some duplicationX * of code.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X    int value, total;XX    printf("This program adds a list of numbers.\n");X    printf("Signal end of list with a 0.\n");X    total = 0;X    printf(" ? ");X    value = GetInteger();X    while (value != 0) {X        total += value;X        printf(" ? ");X        value = GetInteger();X    }X    printf("The total is %d\n", total);X}END_OF_FILEif test 689 -ne `wc -c <'programs/04-Statement-Forms/addlist.c'`; then    echo shar: \"'programs/04-Statement-Forms/addlist.c'\" unpacked with wrong size!fi# end of 'programs/04-Statement-Forms/addlist.c'fiif test -f 'programs/04-Statement-Forms/cardrank.c' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'programs/04-Statement-Forms/cardrank.c'\"elseecho shar: Extracting \"'programs/04-Statement-Forms/cardrank.c'\" \(542 characters\)sed "s/^X//" >'programs/04-Statement-Forms/cardrank.c' <<'END_OF_FILE'X/*X * File: cardrank.cX * ----------------X * Reads in a number between 1 and 13 and writes out theX * appropriate symbol for a playing card of that rank.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X    int n;XX    printf("What is the rank of the card (1-13)? ");X    n = GetInteger();X    switch (n) {X      case  1: printf("Ace\n"); break;X      case 11: printf("Jack\n"); break;X      case 12: printf("Queen\n"); break;X      case 13: printf("King\n"); break;X      default: printf("%d\n", n); break;X    }X}END_OF_FILEif test 542 -ne `wc -c <'programs/04-Statement-Forms/cardrank.c'`; then    echo shar: \"'programs/04-Statement-Forms/cardrank.c'\" unpacked with wrong size!fi# end of 'programs/04-Statement-Forms/cardrank.c'fiif test -f 'programs/04-Statement-Forms/digitsum.c' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'programs/04-Statement-Forms/digitsum.c'\"elseecho shar: Extracting \"'programs/04-Statement-Forms/digitsum.c'\" \(631 characters\)sed "s/^X//" >'programs/04-Statement-Forms/digitsum.c' <<'END_OF_FILE'X/*X * File: digitsum.cX * ----------------X * This program sums the digits in a positive integer.X * The program depends on the fact that the last digit ofX * a integer n is given by n % 10 and the number consistingX * of all but the last digit is given by the expression n / 10.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X    int n, dsum;XX    printf("This program sums the digits in an integer.\n");X    printf("Enter a positive integer: ");X    n = GetInteger();X    dsum = 0;X    while (n > 0) {X        dsum += n % 10;X        n /= 10;X    }X    printf("The sum of the digits is %d\n", dsum);X}END_OF_FILEif test 631 -ne `wc -c <'programs/04-Statement-Forms/digitsum.c'`; then    echo shar: \"'programs/04-Statement-Forms/digitsum.c'\" unpacked with wrong size!fi# end of 'programs/04-Statement-Forms/digitsum.c'fiif test -f 'programs/04-Statement-Forms/leapyear.c' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'programs/04-Statement-Forms/leapyear.c'\"elseecho shar: Extracting \"'programs/04-Statement-Forms/leapyear.c'\" \(727 characters\)sed "s/^X//" >'programs/04-Statement-Forms/leapyear.c' <<'END_OF_FILE'X/*X * File: leapyear.cX * ----------------X * Reads in a year and determines whether it is aX * leap year.  A year is a leap year if it isX * divisible by four, unless it is divisible by 100.X * Years divisible by 100 are leap years only ifX * divisible by 400.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X    int year;X    bool isLeapYear;XX    printf("Program to determine whether a year is a leap year.\n");X    printf("What year? ");X    year = GetInteger();X    isLeapYear = ((year % 4 == 0) && (year % 100 != 0))X                 || (year % 400 == 0);X    if (isLeapYear) {X        printf("%d is a leap year.\n", year);X    } else {X        printf("%d is not a leap year.\n", year);X    }X}END_OF_FILEif test 727 -ne `wc -c <'programs/04-Statement-Forms/leapyear.c'`; then    echo shar: \"'programs/04-Statement-Forms/leapyear.c'\" unpacked with wrong size!fi# end of 'programs/04-Statement-Forms/leapyear.c'fiif test -f 'programs/04-Statement-Forms/liftoff.c' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'programs/04-Statement-Forms/liftoff.c'\"elseecho shar: Extracting \"'programs/04-Statement-Forms/liftoff.c'\" \(446 characters\)sed "s/^X//" >'programs/04-Statement-Forms/liftoff.c' <<'END_OF_FILE'X/*X * File: liftoff.cX * ---------------X * Simulates a countdown for a rocket launch.X */XX#include <stdio.h>X#include "genlib.h"XX/*X * Constant: StartingCountX * -----------------------X * Change this constant to use a different starting valueX * for the countdown.X */XX#define StartingCount 10XX/* Main program */XXmain()X{X    int t;XX    for (t = StartingCount; t >= 0; t--) {X        printf("%2d\n", t);X    }X    printf("Liftoff!\n");X}END_OF_FILEif test 446 -ne `wc -c <'programs/04-Statement-Forms/liftoff.c'`; then    echo shar: \"'programs/04-Statement-Forms/liftoff.c'\" unpacked with wrong size!fi# end of 'programs/04-Statement-Forms/liftoff.c'fiif test -f 'programs/04-Statement-Forms/oddeven.c' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'programs/04-Statement-Forms/oddeven.c'\"elseecho shar: Extracting \"'programs/04-Statement-Forms/oddeven.c'\" \(414 characters\)sed "s/^X//" >'programs/04-Statement-Forms/oddeven.c' <<'END_OF_FILE'X/*X * File: oddeven.cX * ---------------X * Reads in a number and classifies it as even or odd.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X    int n;XX    printf("Program to classify a number as even or odd.\n");X    printf("n = ? ");X    n = GetInteger();X    if (n % 2 == 0) {X        printf("That number is even.\n");X    } else {X        printf("That number is odd.\n");X    }X}END_OF_FILEif test 414 -ne `wc -c <'programs/04-Statement-Forms/oddeven.c'`; then    echo shar: \"'programs/04-Statement-Forms/oddeven.c'\" unpacked with wrong size!fi# end of 'programs/04-Statement-Forms/oddeven.c'fiif test -f 'programs/04-Statement-Forms/signtest.c' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'programs/04-Statement-Forms/signtest.c'\"elseecho shar: Extracting \"'programs/04-Statement-Forms/signtest.c'\" \(491 characters\)sed "s/^X//" >'programs/04-Statement-Forms/signtest.c' <<'END_OF_FILE'X/*X * File: signtest.cX * ----------------X * Reads in a number and classifies it according to its sign.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X    int n;XX    printf("Program to classify a number by its sign.\n");X    printf("n = ? ");X    n = GetInteger();X    if (n > 0) {X        printf("That number is positive.\n");X    } else if (n == 0) {X        printf("That number is zero.\n");X    } else {X        printf("That number is negative.\n");X    }X}END_OF_FILEif test 491 -ne `wc -c <'programs/04-Statement-Forms/signtest.c'`; then    echo shar: \"'programs/04-Statement-Forms/signtest.c'\" unpacked with wrong size!fi# end of 'programs/04-Statement-Forms/signtest.c'fiif test -f 'programs/04-Statement-Forms/timestab.c' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'programs/04-Statement-Forms/timestab.c'\"elseecho shar: Extracting \"'programs/04-Statement-Forms/timestab.c'\" \(568 characters\)sed "s/^X//" >'programs/04-Statement-Forms/timestab.c' <<'END_OF_FILE'X/*X * File: timestab.cX * ----------------X * Generates a multiplication table where each axisX * runs from LowerLimit to UpperLimit.X */XX#include <stdio.h>X#include "genlib.h"XX/*X * ConstantsX * ---------X * LowerLimit -- Starting value for the tableX * UpperLimit -- Final value for the tableX */XX#define LowerLimit  1X#define UpperLimit 10XX/* Main program */XXmain()X{X    int i, j;XX    for (i = LowerLimit; i <= UpperLimit; i++) {X        for (j = LowerLimit; j <= UpperLimit; j++) {X            printf(" %4d", i * j);X        }X        printf("\n");X    }X}END_OF_FILEif test 568 -ne `wc -c <'programs/04-Statement-Forms/timestab.c'`; then    echo shar: \"'programs/04-Statement-Forms/timestab.c'\" unpacked with wrong size!fi# end of 'programs/04-Statement-Forms/timestab.c'fiif test -f 'programs/05-Functions/Makefile' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'programs/05-Functions/Makefile'\"elseecho shar: Extracting \"'programs/05-Functions/Makefile'\" \(1604 characters\)sed "s/^X//" >'programs/05-Functions/Makefile' <<'END_OF_FILE'X# Makefile for cbook/05-Functions/programsX# Created by the ExportAll facilityX# ***************************************************************XXPROGRAMS = \X    gameloop \X    iseven \X    c2ftable \X    fact \X    combine \X    calendar XX# ***************************************************************X# Parameters to control Makefile operationX# Note that the gccx command script must be definedXXCC = gccxXCFLAGS = XX# ***************************************************************X# Entry to bring the package up to dateXXall: $(PROGRAMS)XX# ***************************************************************X# Standard entries to remove files from the directoriesX#    tidy    -- eliminate unwanted filesX#    scratch -- delete derived files in preparation for rebuildXXtidy:X	rm -f ,* .,* *~ core a.out graphics.psXXscratch: tidyX	rm -f *.o *.a $(PROGRAMS)XX# ***************************************************************X# C compilationsXXgameloop.o: gameloop.cX	$(CC) $(CFLAGS) -c gameloop.c

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -