ebook img

C for Engineers and Scientists: An Introduction to Programming With ANSI C PDF

664 Pages·1993·27.11 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview C for Engineers and Scientists: An Introduction to Programming With ANSI C

r</>~ --------- -'•~...>•, ---- :'0 f.., r"'\ .~" \.. ~.y~ I " ',;r ,~ .- (' , :..•. \ '- r"\ <', (- ," ,. , , '", [. ". ~~ c.; A~~.- ~~~-~ ~ '-0~-r ('0 r<~ /(/O' A ,,(' ~-/<..y.\, '~0/' " C; , 1_'<'.(•c•'•• ~, "f'\ I, /:. ~" ONPreface ("'C\r< '(:'C';-, I!)~(',..., ~~0 r A/""\(..''\;'(' r,'f, r\"",\./~ ('/" ( " " .1(' r " <.~.;:' ''''f'<- -: ~",'- '~; ,.'\ <.'".r""<:~:z (..",I' /'~,.,I'\ r ,~)( ~ ....."" ~..,. '..~:, .< /'r t', -,',; /); /' . 'A'; '~ , \.~ I ~rartab{lity.,Portability determines 'the degrelt() whlcl).a prog;am written.on A) /.;1." \. " ." ," ( ,one computet &stem e.at;!pem:,?vedto ally.other sxstem>~enerally,C source -,b,/.(-' It: 'f ~ 'code canl?e moved acrosstpmputer:systemswith little or no modification. For :<::).-- C CX~ ~:ample, C~ource rode written oria""UNIl based \hl~chine'c~.usually be \c ,t: compil~~ on(~~.'~ PS<or mairt.tr~mewit~ alm6~no modificat'iclnsrequired <..' (' %')<, in:~hecode. Withtpe, availaBilityofinexpensive compi1~rsth~t run on personal "', '-:-/, « com.puters, this,portability has,meant that programs d~veloRedat home can be I ~ /:' y' '. ~~used\~Il'PCS,~mmis,andinainfr~mes atW6rk. ~, ,. r" ;;f~ A ,.~ Ve;sdiiiity. D'ep~i;l4ing6~'Ctheuset's orientation, e:'prograrris ~anbe written ,', ,-' ~S: for real-time'process'control, fOxe.ngineering analysis work,.for statistical appli- ~ (C~:(;. '/catioris/~9 develqp,database.ap~li2ations;to c(msb1ict,.op~&tingsysteI)lS,or to A' r wt)!eFOR~ c~mpi1ers~n:? BASIC)nterPreters. \..C~.... (: ~., .(-;~ %)<S A" For thesJ.reasons, lasmore'aIl9.more;:people h~ve triedC, they have found, " (f'rl /''(qt to be a~profesSionallangu~ge haVingan"~nusual'-;ange of capabilities that is': vA.: "-.,.-'" ('- (, [~ r: )-- l/~ enjowble t<;>(workWith.Thf"us, C.has'.ij."q_ined F. QR~ '>01• and CO.BQLas a m~jor <: ,,< progl'aming la/"'n- guage'f/"o*"_r Jfdus/"f~r,~y: ,~ 'r"' .;.r, \. :,,, (z'",""'- r .-1',.,... C': ~~, ~'", Inreeognition)6fthe ifnpqrtant€';lnd wid~pread s,ci7~tificrengineerin:g,and, ~ eN C'n cOOF;..rciaI11S5~pttncelf e:fl.\e Ameri~~nNati~~al StaJ,1dardsIn~ti~te (ANSI) '":/~~ :' J.-- ' _j: began ~t,abliShii\g.a standard for the language, simy.~rto"sta~dards'previously,{. 1';),%, !Ci:' "established/or FO~~~N:"ap.d COBP}' As noted in the forew()r~ to th~1989z' 0f C'(\ '~1J.'~ draf(~f the AI;!SIsta~dard, nee~ for a's!I1gle, cleaFly-defined standard '".... IJ,<), ,,)'~ad a~s~~ in/t~e, C co~~unity,.due hi' a,:}apidly ,~xpanq.ing use:'ot.the' C !C;,:' r 'programming lang~ge and;th~ varie,ty,o..f differing translator implementations' /': '"'«f. AI'~..,that ha~ beenJnd we:e}>eing develop~d,:'~The st~dard was officiallyrati(ied ' b C'~, ('~a.s,Amer~~ .Nati~~al St~nd~rd X3.}59-198~'~~D~mber 14,1989 'and,subse'- <~. 'j- ,,"'/:. qU~I\tlypUD!J~hed~.t~e SPIJt'8 of 1990. "~;.'; (" C:/,. ' A r 'Because bfte's gr6tving importance in-the applications;and academic areas, /;.. ('. ~f' ~th~ predecessor':b';.thist~X!,~4Fi~rt'!3aoka/t2f~as wri'tt;~. Theprimarfl?urpo~,~, ::~ an C~, ~".:"." o£:<.t~seetrli!f editi~p.,"w,as~to maKe::\C;m: :o~'~~ccessible as «applications,t:':j- '\ y \.X' _programmirig(l~nguage~thfn wa~~possiblewith,texts thaf focused OIlC as/a~l1 «f A/)",; advanced"operatihg.syst6ns langu~fge.A second edition of~AFirstBook a(e" ~~'- ('0 irtililded ~xpand~~fcoveraie:of.soft\.vare engirl'eeringroncepts: This pertItitted (b C~ be;l1J~ .,the boo,k,to as .~~introauction( to,:progra~ing.rn' ?-dditi6h,.tob~ing ~.",". .c;:. A'/" )-- ~/ail introduction 'tb Thi~;t~xt retains the' style ~nd' teachingorierttation of' ~.'«~"(., /<;.:~/. its predeces~or but. is"spedfical~¥ o;i~~ted tow.~r,!engine~ring"and scien~ic ., (r:: applicati'ons. r. >_. v, (.\ ""( 'i» ,~ ~ ~ \-'''~./2 f \I""*< .••.......•••. •. :~ /" r .;(). . ,(,.'.~ /.7'. /' !~ \ if. 1'-.("" /' r ' 'r:.:. /0,,'"'' ~t'l. \ ,.., B~Sk '\o ~~ .r~. / D"i'"s't..h;ctiv,/e,'......Fe{tit.res ofTh~i's" .. ~~ A~'"'>~I' " c,,_ ~ ::.;~-- 'r-~._ K> \. Wntmg Style. I firmly.,beheve that mtroductoryx texts'do not teach students - f" it f r \,;.:-p.rofesJors te<achs,tudefits. An iritJ;odudory textb601<,if is.to be'~seful,6\ust i. A/;~/. ~ r 9~~the/primarY('spppO?ti(la~ct~?:t~ the III~~dingrolf" ot th~profeS$~f'O~te \..I.),. the -profesS9r/.setsthe stage,;,.t\Owever,~thetextbook 1n~t encour;age, nurture, <,' ~' A , and' assist the,.student.-inacquiring and.,'~owning'~ the' nlat~ria( presented. in A r\ '%J./'~ r- ~," class. Togo thi~the~text'~l1stbe Wtl!!enin a,manne}'.thatrr~a~ess~se to the.<t' "/' ,.. ..,....... t (' /.. j--..." r' <. I' . ' '\ r, ,"., /"\.r•.v...i.iir f ~,;<('~rC'~) A/'Af</:('(':. j-" .<~~ \.''/"r'.,,'-" .' " > \. I~X; r,',,fr~.~. /'-:r~ ,.- "'-.j.•~.J C't~.\ <'''O;:f''"' "/\'A~.•....... r-- \ .X:/ Preface student. One of the distinctive features of this book is that it has been written for the student. As one of the reviewers has said, "This book addresses the student and not the professional." Thus, first and foremost, I feel the writing style used to convey the concepts presented is the most important aspect of the text. Modularity. C, by its nature, is a modular langUage. Thus, the connection between C functions and modules is made early in the text, in Section 1.2,and continues throughout the book. To stress the modular nature of C, the first complete main () function illustrates calling four other functions. The first program that can be compiled is then presented, which calls the printf () function. The idea ofargument passing into modules isalso made early,in Section 1.3, with the use of the printf () function. Inthis manner, students are introduced to functions and argument passing asa natural technique ofprogramming. Software Engineering. Rather than simply introduce students to C, this text introduces students to the fundamentals ofsoftware engineering. This introduc- tion begins with Section 1.1,which introduces algorithms and the various ways that an algorithm can be described. An example illustrating three algorithms for summing the numbers from. 1 to 100 (Figure 1-4) is used to make the discussion of algorithms more tangible to students. The increased emphasis on software engineering is supported by a section (Section1.5)on top-down program development. Here the importance ofunder- standing the problem and selecting an appropriate algorithm is highlighted and the relationship between analysis, design, coding, and testing introduced. Prob- lem solving within this context is stressed throughout the text. Applications. Engineering and scientific examples are used throughout the text to illustrate the concepts presented. In addition, the majority ofthe chapters have a section consisting of two specific applications relating to the material presented in the chapter. Many of the applications are of the "tried and true" variety and are not unique to this book. However, some interesting new applications have been added, such as the study of acid rain, the calculation of pollen counts, the operation oftelephone switching networks, and the construc- tion of a user-written random number generator that are not typically found in introductory texts. Additionally, Chapter 9 is completely devoted to numerical applications and is a mini-introduction to numerical techniques in and of itself. Emphasis on ANSI C.Although ANSI C is emphasized throughout the text, pre-ANSI C constructs are also shown for those of you who will be using a non-ANSI compiler. Generally, the major difference of note is in Chapter 6, where user-written functions are introduced. For these functions ANSI C requires asingle function header line that includes argument declarations, while pre-ANSI compilers require argument declarations on a separate line. Also, the declaration of functions in ANSIC,called function prototypes, includes the data types of all arguments, while pre-ANSI C omits the argument declarations. Introduction toPointers. One of the unique features of this text is its method of introducing pointers. This is done by first using the printf () function to ix Preface display a variable's address so that the student can "see" what an address is. This approach, which was used in a A First Book of C, always seemed a more logical and intuitive method of understanding pointers than the alternative indirection description with no display. Sincethe publication ofA First Book of C,the use ofthe print f () function to display addresses has become a standard way of introducing pointers. Although this approach, therefore, is no longer a unique feature of the book, I am very proud of its presentation, and continue to use it in this text. Program Testing. Every single C program in this text has been successfully compiled and run under Borland's Turbo CCompiler. The programs have been written using features fully supported under ANSI C. A source diskette of all programs is available to adopters. Pedagogical Features To facilitate my goal of making C accessible as a first level course, I have continued to use the following pedagogical features: End of Section Exercises. Almost every section in the book contains numerous and diverse skill builder and programming exercises.Additionally, solutions to selected exercises are provided in an appendix. Pseudocode and Flowchart Descriptions. As in A First Book of C,pseudocode is stressed throughout the text. Although flowcharts were used in A First Book of C,no explicit definition or introduction to flowchart symbols was presented. In this edition we have added additional material on flowchart symbols and the use of flowcharts in visually presenting flow-of-control constructs. Common Programming Errors and Chapter Review. Each chapter ends with a section on common programming errors and a review of the main topics covered. Appendices and Supplements An expanded set of appendices has been provided in C for Engineers and Scientists. In addition to the three appendices taken from A First Book of C on Operator Precedence,ASCIIcodes,and I/O-Standard ErrorRedirection, the new appendices contain material on Program LifeCycle;using the DOS,UNIX,VAX, and PRIME operating systems; using Borland's Turbo C Compiler; and using Microsoft's C Compiler. Additionally, a printed solutions manual is available containing solutions (with comments) to programming exercisesnot included in Appendix H of the text. A so~rce diskette of solutions to all programs in the book is available to adoptors of the text. x Acknowledgments Acknowledgments Cfor Engineers and Scientists is a direct result of the success (and the limitations) of its predecessor, A First Bookof C. In this regard, my most heartfelt acknowl- edgment and appreciation goes to the instructors and students who found the earlier edition to be of service to them in their respective quests to teach and learn C. Once an edition devoted to engineering and scientific applications was planned, its completion depended on many people other than myself. For this I especially want to thank the staff of West Publishing Company for their many contributions. These included the continuous faith and encouragement of my editor, Richard Mixter, and developmental editor, Keith Dodson, and the many suggestions and enthusiastic work of the production editor, Thomas ModI, and promotion manager, Ellen Stanton. The direct encouragement and support of my dean at Fairleigh Dickinson University, Dr. Paul Lerman, must also be acknowledged. Without his support and the support of my chairman, Dr. G. Naadimuthu, this text could not have been written. I also wish to express my gratitude to the individual reviewers listed on the next page. Each of these people provided suggestions and critical comments that have made an invaluable contribution to the quality of this text. Finally, I wish to acknowledge the patience, understanding, and love pro- vided by my wife and partner, Rochelle. Gary Bronson xi Acknowledgments The author thanks these reviewers for their knowledgeable help in the comple- tion of this book. Farzan Abdolsalami Paul I-Hai Lin Trinity University Indiana University/Purdue University Farrokh Atlarzadeh at Fort Wayne University of Houston-University Park Robert D. Logcher Lorraine Callahan Massachusetts Institute of Technology (formerly) Northern Arizona University Luegina C. Mounfield Louisiana State University Katy Disney Mission College David Richards David Eberly Loyola College University of North Carolina at Chapel Hill Howard Silver Rhonda Ficek . Fairleigh Dickinson University Moorhead State University Susan M. Simons Memphis State University Roy J. Fuller University of Arkansas at Fayetteville Neil R. Sorensen Weber State University Gordon W. Hoagland Ricks College Donald Yee Mesa Community College xii

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.