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 part of th is pu blication m ay be reprod u ced , stored in a retrieval system , 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

O F F IC E S

?

?

?

?

?

B a n g a lo re

C o ch in

H y d era b a d

K o lk a ta

M u m b ai

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

FPR-3108-295-PROG PROB SOL TH C LANG-BAN

Typeset at : Kalyani Computer Services, Delhi.

?

?

?

?

?

C h en n a i

G u w a h a ti

J a lan d h a r

L u ck n o w

R a n 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

C¡ª5519/012/08

Printed at : Ajit Printing Press, Delhi.

Contents

Contents

IX

1. Introduction to Programming ............................................................................................... 1

1.1

1.2

1.3

1.4

1.5

1.6

1.7

1.8

1.9

The Basic Model of Computation ....................................................................................................... 1

Problem Solving .................................................................................................................................. 2

Algorithms .......................................................................................................................................... 5

Flow-Charts ...................................................................................................................................... 10

Programming Languages .................................................................................................................. 20

Compilation ....................................................................................................................................... 25

Linking and Loading ......................................................................................................................... 26

Testing and Debugging .................................................................................................................... 26

Documentation ................................................................................................................................. 31

2. Algorithms for Problem Solving ........................................................................................ 39

2.1

2.2

2.3

2.4

2.5

2.6

2.7

2.8

2.9

2.10

2.11

2.12

2.13

2.14

2.15

2.16

Exchanging Values of Two Variables ................................................................................................. 39

Summation of a Set of Numbers ........................................................................................................ 40

Decimal Base to Binary Base Conversion ......................................................................................... 40

Reversing Digits of an Integer .......................................................................................................... 42

GOD (Greatest Common Divisor) of Two Numbers ........................................................................... 43

Test Whether a Number is Prime ....................................................................................................... 44

Organize Numbers in Ascending Order ............................................................................................ 44

Find Square Root of a Number .......................................................................................................... 45

Factorial Computation ...................................................................................................................... 47

Fibonacci Sequence .......................................................................................................................... 48

Evaluate ¡®Sin x¡¯ as Sum of a Series .................................................................................................... 48

Reverse Order of Elements of an Array ............................................................................................. 49

Find Largest Number in an Array ...................................................................................................... 49

Print Elements of Upper Triangular Matrix ........................................................................................ 50

Evaluate a Polynomial ....................................................................................................................... 50

Multiplication of Two Matrices ........................................................................................................ 51

3. Introduction to ¡®C¡¯ Language ............................................................................................. 54

3.1

3.2

3.3

3.4

3.5

3.6

3.7

3.8

3.9

Character set ..................................................................................................................................... 54

Variables and identifiers .................................................................................................................... 56

Built-in Data Types ........................................................................................................................... 58

Variable Definition ............................................................................................................................ 64

Arithmetic operators ......................................................................................................................... 64

Expressions ....................................................................................................................................... 70

Constants and Literals ...................................................................................................................... 72

Simple Assignment Statement .......................................................................................................... 75

Basic Input/Output Statement .......................................................................................................... 75

4. Conditional Statements and Loops .................................................................................... 89

4.1

4.2

4.3

4.4

4.5

4.6

4.7

4.8

4.9

4.10

Decision Making within a Program ................................................................................................... 89

Conditions and Relational Operators ................................................................................................ 89

Logical Connectives ......................................................................................................................... 90

If statement ....................................................................................................................................... 90

If-else statement ............................................................................................................................... 95

Loops ............................................................................................................................................... 103

While loop ....................................................................................................................................... 104

Do while ...........................................................................................................................................107

For loops ..........................................................................................................................................109

Nested Loops .................................................................................................................................. 113

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

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

Google Online Preview   Download