Programming and Problem Solving Through C Language

Programming and Problem Solving Through `C' Language

Programming and Problem Solving Through `C' Language

M3 - R4

STRICTLY AS PER NEW DOEACC SYLLABUS

RAMESH BANGIA

B.Sc., Dip. Comp. Sc. (IIT D) Formerly: Incharge Computer Centre, Hindustan Copper Limited, New Delhi Ex. Managing Editor: Software Today

FIREWALL MEDIA (An Imprint of Laxmi Publications Pvt. Ltd.)

BANGALORE CHENNAI COCHIN

GUWAHATI HYDERABAD

JALANDHAR KOLKATA LUCKNOW MUMBAI RANCHI

NEW DELHI BOSTON, USA

C opyrigh t ? 2013 by L axm i P u blication s P vt. L td . A ll righ ts reserved . N o partofth is pu blication m ay be reprod u ced ,stored in a retrievalsystem ,or tran sm itted in an y form or by an y m eans,electronic,m echanical,ph otocopyin g, record in g or oth erw ise w ith ou t th e prior w ritten perm ission of th e pu blish er.

P u blish ed by :

FIREWALL MEDIA

(A n Im prin t of L axm i P u blication s P vt. L td .) 113, G olden H ou se, D aryagan j, N ew D elh i-110002

P h on e : 011-43 53 25 00 F ax : 011-43 53 25 28

w w w .laxm ipu blication in fo@ laxm ipu blication

P rice : 295.00 O n ly.

N ew E d ition

B a n ga lo re C o ch in H yd erab ad K o lk a ta M um bai

O F F IC E S

080-26 75 69 30 0484-237 70 04,405 13 03 040-24 65 23 33 033-22 27 43 84 022-24 91 54 15,24 92 78 69

C h en n ai G u w a h a ti J a lan d h a r L u ck n ow R an ch i

044-24 34 47 26 0361-251 36 69,251 38 81 0181-222 12 72 0522-220 99 16 0651-221 47 64

FPR-3108-295-PROG PROB SOL TH C LANG-BAN Typeset at : Kalyani Computer Services, Delhi.

C--5519/012/08 Printed at : Ajit Printing Press, Delhi.

Contents

Contents

IX

1. Introduction to Programming ............................................................................................... 1 1.1 The Basic Model of Computation ....................................................................................................... 1 1.2 Problem Solving .................................................................................................................................. 2 1.3 Algorithms .......................................................................................................................................... 5 1.4 Flow-Charts ...................................................................................................................................... 10 1.5 Programming Languages .................................................................................................................. 20 1.6 Compilation ....................................................................................................................................... 25 1.7 Linking and Loading ......................................................................................................................... 26 1.8 Testing and Debugging .................................................................................................................... 26 1.9 Documentation ................................................................................................................................. 31

2. Algorithms for Problem Solving ........................................................................................ 39 2.1 Exchanging Values of Two Variables ................................................................................................. 39 2.2 Summation of a Set of Numbers ........................................................................................................ 40 2.3 Decimal Base to Binary Base Conversion ......................................................................................... 40 2.4 Reversing Digits of an Integer .......................................................................................................... 42 2.5 GOD (Greatest Common Divisor) of Two Numbers ........................................................................... 43 2.6 Test Whether a Number is Prime ....................................................................................................... 44 2.7 Organize Numbers in Ascending Order ............................................................................................ 44 2.8 Find Square Root of a Number .......................................................................................................... 45 2.9 Factorial Computation ...................................................................................................................... 47 2.10 Fibonacci Sequence .......................................................................................................................... 48 2.11 Evaluate `Sin x' as Sum of a Series .................................................................................................... 48 2.12 Reverse Order of Elements of an Array ............................................................................................. 49 2.13 Find Largest Number in an Array ...................................................................................................... 49 2.14 Print Elements of Upper Triangular Matrix ........................................................................................ 50 2.15 Evaluate a Polynomial ....................................................................................................................... 50 2.16 Multiplication of Two Matrices ........................................................................................................ 51

3. Introduction to `C' Language ............................................................................................. 54 3.1 Character set ..................................................................................................................................... 54 3.2 Variables and identifiers .................................................................................................................... 56 3.3 Built-in Data Types ........................................................................................................................... 58 3.4 Variable Definition ............................................................................................................................ 64 3.5 Arithmetic operators ......................................................................................................................... 64 3.6 Expressions ....................................................................................................................................... 70 3.7 Constants and Literals ...................................................................................................................... 72 3.8 Simple Assignment Statement .......................................................................................................... 75 3.9 Basic Input/Output Statement .......................................................................................................... 75

4. Conditional Statements and Loops .................................................................................... 89 4.1 Decision Making within a Program ................................................................................................... 89 4.2 Conditions and Relational Operators ................................................................................................ 89 4.3 Logical Connectives ......................................................................................................................... 90 4.4 If statement ....................................................................................................................................... 90 4.5 If-else statement ............................................................................................................................... 95 4.6 Loops ............................................................................................................................................... 103 4.7 While loop ....................................................................................................................................... 104 4.8 Do while ...........................................................................................................................................107 4.9 For loops ..........................................................................................................................................109 4.10 Nested Loops .................................................................................................................................. 113

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download