/* ECP: FILEname=fig1_1.c */
/* 1*/ #include <stdio.h>
/* 2*/ main( void )
/* 3*/ {
/* 4*/ printf( "Is there anybody out there?\n" );
/* 5*/ return 0;
/* 6*/ }
/* ECP: FILEname=fig1_2.c */
/* 1*/ #include <stdio.h>
/* 2*/ /* Read Items, Compute Their Average */
/* 3*/ main( void )
/* 4*/ {
/* 5*/ int ItemsRead = 0;
/* 6*/ double ThisItem, Sum = 0.0;
/* 7*/ printf( "Enter as many items as you want\n" );
/* 8*/ printf( "Terminate with non-double or EOF marker\n" );
/* 9*/ while( scanf( "%lf", &ThisItem ) == 1 )
/*10*/ {
/*11*/ ItemsRead++;
/*12*/ Sum += ThisItem;
/*13*/ }
/*14*/ printf( "The average of %d items was %f\n",
/*15*/ ItemsRead, Sum / ItemsRead );
/*16*/ return 0;
/*17*/ }
/* ECP: FILEname=fig1_3.c */
/* 1*/ #include <stdio.h>
/* 2*/ unsigned long int
/* 3*/ Factorial( unsigned long int N )
/* 4*/ {
/* 5*/ int i;
/* 6*/ unsigned long int Answer = 1;
/* 7*/ for( i = 1; i <= N; i++ )
/* 8*/ Answer *= i;
/* 9*/ return Answer;
/*10*/ }
/*11*/ main( void )
/*12*/ {
/*13*/ int i;
/*14*/ const int MaxNum = 12;
/*15*/ printf( " N N!\n" );
/*16*/ for( i = 0; i <= MaxNum; i++ )
/*17*/ printf( "%2d %10lu\n", i, Factorial( i ) );
/*18*/ return 0;
/*19*/ }
/* ECP: FILEname=fig1_5.c */
/* 1*/ #include <stdio.h>
/* 2*/ /* Compute Frequency Of Lottery Numbers */
/* 3*/ #define MaxNum 49 /* Numbers Range From 1 To 49 */
/* 4*/ main( void )
/* 5*/ {
/* 6*/ int Count[ MaxNum + 1 ]; /* Frequency Of Each Number */
/* 7*/ int Number;
/* 8*/ int i;
/* 9*/ for( i = 0; i <= MaxNum; i++ )
/*10*/ Count[ i ] = 0;
/*11*/ /* Note: No Prompting For Input */
/*12*/ while( scanf( "%d", &Number ) == 1 )
/*13*/ if( Number < 1 || Number > MaxNum )
/*14*/ printf( "Out of range number ignored\n" );
/*15*/ else
/*16*/ Count[ Number ]++;
/*17*/ /* Output The Data, Seven Numbers Per Line */
/*18*/ for( i = 1; i <= MaxNum; i++ )
/*19*/ {
/*20*/ printf( "%3d:%4d", i, Count[ i ] );
/*21*/ if( i % 7 == 0 )
/*22*/ printf( "\n" );
/*23*/ else
/*24*/ printf( " " );
/*25*/ }
/*26*/ return 0;
/*27*/ }
/* ECP: FILEname=fig1_6.c */
/* 1*/ /* Return 1 if Str1 And Str2 Are Equal */
/* 2*/ int
/* 3*/ IsEqual( char Str1[ ], char Str2[ ] )
/* 4*/ {
/* 5*/ int i;
/* 6*/ for( i = 0; Str1[ i ] == Str2[ i ]; i++ )
/* 7*/ if( Str1[ i ] == '\0' )
/* 8*/ return 1; /* Equal Strings */
/* 9*/ return 0; /* Not Equal */
/*10*/ }
/* ECP: FILEname=fig1_8.c */
/* 1*/ #include <stdio.h>
/* 2*/ /* Read And Write Strings */
/* 3*/ #define MaxLen 512
/* 4*/ main( void )
/* 5*/ {
/* 6*/ char Str[ MaxLen + 1 ];
/* 7*/ while( scanf( "%s", Str ) == 1 )
/* 8*/ printf( "I read %s\n", Str );
/* 9*/ return 0;
/*10*/ }
/* ECP: FILEname=fig1_9.c */
/* 1*/ struct Complex
/* 2*/ AddComplex( struct Complex X, struct Complex Y )
/* 3*/ {
/* 4*/ struct Complex Sum;
/* 5*/ Sum.Real = X.Real + Y.Real;
/* 6*/ Sum.Imag = X.Imag + Y.Imag;
/* 7*/ return Sum;
/* 8*/ }
/* ECP: FILEname=fig1_10.c */
/* 1*/ #include <stdio.h>
/* 1*/ void
/* 2*/ Swap( int * const X, int * const Y )
/* 3*/ {
/* 4*/ int Tmp;
/* 5*/ Tmp = *X;
/* 6*/ *X = *Y;
/* 7*/ *Y = Tmp;
/* 8*/ }
/* 1*/ main( void )
/* 2*/ {
/* 3*/ int A = 5, B = 7;
/* 4*/ Swap( &A, &B ); /* Must Pass The Address */
/* 5*/ printf( "%d %d\n", A, B );
/* 6*/ return 0;
/* 7*/ }
/* ECP: FILEname=fig1_11.c */
/* 1*/ typedef struct Complex Complex;
/* 2*/ void AddComplex( const Complex *X, const Complex *Y, Complex *Sum )
/* 3*/ {
/* 4*/ Sum->Real = X->Real + Y->Real;
/* 5*/ Sum->Imag = X->Imag + Y->Imag;
/* 6*/ }
/* ECP: FILEname=fig1_12.c */
/* 1*/ #include <stdio.h>
/* 2*/ /* Read Items, Compute Their Average */
/* 3*/ main( void )
/* 4*/ {
/* 5*/ FILE *Fp; /* File Pointer */
/* 6*/ char FileName[ 256 ]; /* File Name */
/* 7*/ int ItemsRead = 0;
/* 8*/ double ThisItem, Sum = 0.0;
/* 9*/ printf( "Enter input file: " );
/*10*/ if( scanf( "%s", FileName ) != 1 ||
/*11*/ ( Fp = fopen( FileName, "r" ) ) == NULL )
/*12*/ {
/*13*/ fprintf( stderr, "Cannot open input file\n" );
/*14*/ return 1;
/*15*/ }
/*16*/ while( fscanf( Fp, "%lf", &ThisItem ) == 1 )
/*17*/ {
/*18*/ ItemsRead++;
/*19*/ Sum += ThisItem;
/*20*/ }
/*21*/ printf( "The average of %d items was %f\n",
/*22*/ ItemsRead, Sum / ItemsRead );
/*23*/ return 0;
/*24*/ }
/* ECP: FILEname=fig2_1.c */
/*
* A Simple First Program.
* MW, 10/13/95
*/
/* 1*/ #include <stdio.h>
/* 2*/ main( void )
/* 3*/ {
/* 4*/ printf( "Testing 123\n" );
/* 5*/ }
/* ECP: FILEname=fig2_2.c */
#include<stdio.h>
main(void){printf("Testing 123\n");}
/* ECP: FILEname=fig2_3.c */
/* 1*/ /* This comment ends early on the next line.
/* 2*/ * This is not in the comment!
/* 3*/ * Neither is this; the next line is also an error.
/* 4*/ */
/* 5*/ #include <stdio.h>
/* 6*/ main( void )
/* 7*/ {
/* 8*/ printf( "Testing 123\n" );
/* 9*/ }
/* ECP: FILEname=fig2_4.c */
/* 1*/ #include <stdio.h>
/* 2*/ main( void )
/* 3*/ {
/* 4*/ int First = 12, Second, Third = 6;
/* 5*/ Second = 8;
/* 6*/ printf( "The ints: %d %d %d\n", First, Second, Third );
/* 7*/ First = Third;
/* 8*/ printf( "The ints: %d %d %d\n", First, Second, Third );
/* 9*/ Third += Second;
/*10*/ printf( "The ints: %d %d %d\n", First, Second, Third );
/*11*/ First = Second + Third;
/*12*/ printf( "The ints: %d %d %d\n", First, Second, Third );
/*13*/ First++;
/*14*/ ++Second;
/*15*/ printf( "The ints: %d %d %d\n", First, Second, Third );
/*16*/ Third = First++ + ++Second;
/*17*/ printf( "The ints: %d %d %d\n", First, Second, Third );
/*18*/ }
/* ECP: FILEname=fig2_5.c */
/* 1*/ #include <stdio.h>
/* 2*/ main( void )
/* 3*/ {
/* 4*/ double A = 373737.0;
/* 5*/ double B;
/* 6*/ B = A*A*A + 0.37/A - A*A*A - 0.37/A;
/* 7*/ printf( "The value of B is %f.\n", B );
/* 8*/ }
/* ECP: FILEname=fig2_13.c */
/* 1*/ /* Faculty Profile Fields */
/* 2*/ #define Sex 0x0001 /* On If Female */
/* 3*/ #define Minority 0x0002 /* On If In A Minority Group */
/* 4*/ #define Veteran 0x0004 /* On If Veteran */
/* 5*/ #define Disabled 0x0008 /* On If Disabled */
/* 6*/ #define UScitizen 0x0010 /* On If Citizen */
/* 7*/ #define Doctorate 0x0020 /* On If Holds A Doctorate */
/* 8*/ #define Tenured 0x0040 /* On If Tenured */
/* 9*/ #define TwelveMonth 0x0080 /* On If On 12 Month Contract */
/*10*/ #define Visitor 0x0100 /* On If Not Permanent Faculty */
/*11*/ #define Campus 0x0200 /* On If Work Is At Main Campus */
/*12*/ #define Rank 0x0c00 /* Two Bits To Represent Rank */
/*13*/ #define Assistant 0x0400 /* Assistant Professor */
/*14*/ #define Associate 0x0800 /* Associate Professor */
/*15*/ #define Full 0x0c00 /* Full Professor */
/*16*/ #define College