You are on page 1of 104

4

C b
C-N G
4.1 C b
(Problem Solving Techniques)
EE, EP N
. EP . E
P N , PH
GJ P .
G , I A
NJ CFA. C F,
(design) G NJ G A.
EP NO, , O,
O L . K
I .
NO, (sentences) I c
. C O O .
N M .
C M IP O K,
G NJ ( Intermediary Language) A.
K O. M .
G N N EP
N N. G
N A. , I
M A (Flow Chart) L
P (Pseudo Code) A .
L . E
GO A
. .
O , K
H . E GP ,
L k QQ
200

O QQ O F . H
P
E FJ
. O K P F
J . 4.1-
. F PH
PA. 4.2- .

A,A,BB

C=A+B

C C
C

B B
C

A > B?

4.1

201

A A
C

k, Of

4.2

PH F,
C=A+B

C .
G (equal to) P (=) F F
, G (equation) O
M. J P (statement) ,
F A, B AP F
, C- F F
, F . , MF
,
A=A+1

. A- FH ,
F F e A- J FA.
, A- F A.
A=A+B

GM . ,
A+B=A

202

. F, F M F
.
EP A E
. C CP H
CP .
K C
E .
J C I K.
CP. , C
PH (Concepts)
A.
K C K .
O CP. ,
. OL
? H (Connectors) CP C
b. F PH .
A
O PA. F
O P.
4.3- :

4.3

203

O
L. I K
. CP O K
. M C
,
K I .
, GO
.
W CP
. , b A
. .
K . G
CF F
.
J c, , A
A 4.4- .

c, ,
,

c,

=c**

4.4

204

4.5, 0L 3 J ,
F F A.

N
N
N

N = 0?

=
NN
= 1?
1?

4.5
205

=
NN
= 2?
2?

=
NN= 3?
3?

no

4.6, O CP
P A.

a, b, c

b b< <c?

aa<<b?
b?

a a<<c?
?

b C
b

cc
C

4.6

206

a C

4.7, G (Quadratic equation) b


N A.

a,

a, b,
b, cc

d=b2-4ac

aa ==0?

d d< <0?
0?

d d= =0?
0?

e=d
r1=(b+e)/2a

M
r1 r2
M, r1,

TK
TK
M
M

r = -b/a

M,
M r,r r

4.7
207


n=1,n=1,
sum=0

n<=100?
n<=100
?
Sum
Sum
OJ
OJ

aa

Sum=sum+
Sum=sum+a
a

4.8

208

4.9, (Integer),
(prime number) bQ
A.


nn
i=2

i<n?

i=i+1

end

4.9

209

n i

4.10, 1+2+3+............+ n K
1000 , eC
(smallest integer) P A.

i=1, i=1,
sum=1

sum,

sum, ii
OJ
OJ

sum<10
sum<100?
0?

i=i+1
i=i+1
sum=sum+i
sum=sum+

4.10

4.1.1 G
(Fundamental Conditional and Control Structures)
EP L PJ (Computer pseudo code)
G (step) EP P
. A P O
K EP L P
. A
EP
. . E
P M Cw
. MAl?
210

M Cw P
. Cw .
, , , O .
PML
A.
F A. FJ
. M
AJ F W MM. CP N
. W MM
Cw P. M
, c M FL.
, Q W M

J.
Cw HA
. G FJ
.
b , c, W M
m. , M
K? ,
M.
M F P.
c . .
CP N, F P W
M. W M CP.
, Cw LL C
A. , ,
K. E A.
A FJ A CwO
. L c M
F .
J. FF
L
. H, e K
J. , Cw AM.
EP L P .
211

EP, M CwO .
F . EP O,
M . M
J CF JC .
F , e
e A. F
EE GA.
, e c
.
K  (Sequencing)

W H K J
A.
K .
4.1.1.1 AHK (Branching)
N AHK (Two-way branching)

M .
M . M, P
AHK . M
A A. O
Fd. F O F
d. AHK
.
:
If A > B Then Print A, Otherwise Print B

If......Then.......Else .
J Q, If..... Then
. H F Q,
, .
:
If you find anyone there, then say hello

N AHK (Multi-way Branching)

C M, A F
212

. , Q ?
M O F .
FL J, O
Ed J. N A
HK A. W F
MA .

i=1, i=1,
sum=1

=0
=1
N

sum<100?
sum<10
0?

4.11

213

=3
=2

:
If n is 0 then print Zero
1 then print One
2 then print Two
3 then print Three

4.1.2 (Iteration)
GJ (Definite Iteration)

.
, PH e e .
, e F
F. i.
, , J
P.
O, E F
PFA. G
J A. NJ, P
H A E
. P
P (Index veriable) P (Control Variable)
A.
P F
G :
1) PJ F F
.
2) PJ F (v) F F
H, Q F
bQ .
3) M Q,
u G.
u
PJ F .
u

G , K e
.
214

4) M Q,
u

F .

KH .

4.12 GJ MA.
F, FM A (Loop)
.

i=1

i<=1000
i<=1000?
?

i=i+1

K
4.12

C GO, F
F E .
, 1+2+3+..... +n J,
eC n- F .
. M
F. GFM .

E .
E . M A G
KF . ,
GF (Indefenite Iteration) A.
K (Sequencing), AHK (Branching),
(Interation) A F
Ed .
215

4.1.3 L P (Pseudo Code)


PH E G
F, L P
F . L P ,
A N JG EP N
. AF c
; L . EP NO
H . L P
J A.
I C F . I
CP. ,
F .
F .
K ,
P O
. K (Indentation) ,
. L PJ
M O K .
F AHK, F
L PJ
:
* If.... then............else.............
* If....... then..............
* For.............. to........do.....
* While.............do.........
C P:

If a > b then print a else print b

While sum < 100 do


sum = sum + i
i=i+1

If a < 10 then b = c + d
For i = 1 to 20 do
n=n+i

216

, K
,
F .
W :
While......do

no

a > b?

yes

no

a-
Print a
C

b-
Print b
C

a<10?

yes
b=c+d

i=1

no

i<=20?

yes

no

sum< 1000?

n=n+i
i=i+1

yes
sum = sum+i
i=i+1

4.13

,
, O
. O PH
GP H,
M. , EP KJ
G .
O C . K,
H P c OA MA.
FJ b C L
P W . ,
L P H, J F
F .
217

P
start
read length, breadth and height.
volume = length x breadth x height
print volume
end

, K
.
u


start
read n
if n is
0 then write zero
1 then write one
2 then write two
3 then write three
end

O CP P
start
read a, b, c
if a < b then
(if a < c then
print a
else
print c
)
else
(if b < c then
print b
else
print c )
end

218

G b
start
read a, b, c
if a = 0 then
(
write this is not a quadratic equation
exit
)
else
find d = b2 - 4ac
if d < 0 then
write imaginary roots
else
if d = 0 then
r = -b/a
write equal roots
write r, r
else
r1 = (-b + d)/ 2a
r2 = (-b - d)/2a
write unequal roots
write r1, r2
end

100 J O
start
sum = 0
n=1
while n <= 100 then do
read a
sum = sum + a
n= n+1
print sum
end


start
read n
for i = 1 to n-1 do
if i divides n then
(write not a prime
exit program
)
write prime number
end

219

J
start
i=1
sum = 1
while sum < 1000 do
i=i+1
sum = sum + i
print i and sum
end

C P
If... then....else If.... then..... else
. O O
.
u


O . K
H .
u

EF P ,
P F
.
u

u
L PJ ,
EP G K F, G
N EP G P I O
.

4.1.4 K (Walkthrough)
G F , b N M
K L P
. C bM F
G
. L P
, PH NJ
MF G A. G
, C b N K K
F . , A , L
P K KF
. K , bP (Algorithm)
220

. H, L
P KF N .
bP , W
:
(finite) EJ G (steps)
.
u

u
G, M IP
GJ .

G, G F
F, GJ
.
u

u
G,
.

bP L P
.
EP
KF N, F K .
AF walkthrough A. ,
. EP
A . (Start) PH
JL . FL,
P P J c E
. , Ed
.
k Q, PH PK
F .
F F .
N E KF . CP
G, FL A
O E E. N K
FF G.
Of Q, PO
F OJ .
221

4.1.5 G
CP G O. , CP G
L P L
. J G O. ,
J IK C
N . ,
II .
GL M J.
, I K CJ A, I
M P CF A,
EJ M.
GJ , I A E
. CC F W E K
O MM .
K E K
. J L P. M
FA. , CP C
. ,
QQ HK I O PM .
HK P O
A. K G N
I .
G , C CP
C HK . CP C
P M , K C
M N P F
. G F G .
L P A
CP , K C e e HK
.
L P
F, G A
FM .
O F
. , L P
F, GL N F
222

M . H, EP G
I O EAM.
G F L
W (Top Down Approach) A.
GJ, CEJ
A. CP CO M A bM
PA. EP G
, N L
, (procedures) A A,
, A N
A A, (data) .
G A. C CP C
, A
J, (Object Oriented
Approach) A. G I
P.
J J G
, C++ EP N A
. P MK .
L W J
M A. G
N H.

KJ G .
C:

N:

a1, a2,....... AP .

eC P.

, , EL
A 98 ( ?)
G F F .

FJ
223

G
F .

L P

Read 100 numbers and put them in an array, as a(1), a(2) etc.
Do for i = 1 to 99
Find the smallest of a(i) to a(100)
Let the smallest number be at the jth position
Interchange a(i) and a(j)
Output a(1), a(2) ... a(100)

W CP E Q,
C O b M .
u
k , OJ
u
FJ eC P
u

E A A
M P F.
F Q.
GJ, CE
b .
:
For Count = 1 to 100 do
Read a(count)

N OJ .
a(1) a(100) J O eC
P:
Let i = 1
Let position = 1
Let min = a(i)
For n = i+1 to 100 do
If a(n) < min then
min = a(n)
position = n
Let j=position

224

a(i) a(i)

F :

Let temp = a(i)


a(i) = a(j)
a(j) = temp

, F HA .
a(i) = a(j)
a(j) = a(i)

, G a(i)-
F A.

4.2 C-N G - P
G I
G N C-N.
& F Qv .KC, CN A. F, Qv
F
, C-N N FA. C-N,
F I; A ; F
(Portability) . EPJ
, M P CP
EPJ GM .
F A. C-N
P (Operators) (Commands)
. (Operating Systems), G H
(Compilers), L (Text Processors),
(Database Management Systems) M
C-NJ .
IP (Application Software)
C-N I .
C-N W
:

PL (Constants)

P (Identifiers)

GP (Punctuation)

C (Keywords)
225

M
(tokens) A. GH CP
, GL F M
A.
number = number + 1;

. F M
:
number -

P (P)

PL

GP

, , P, PL, P
MO . C-N GF if, while, for
C A. PH
F .
F H FJ C P
.
4.2.1 PL (Constants)
PL .
. ,
, . PL GL
F F . PL A
, F P
. PL .
. F O (decimal point)
. , ,
O, A C P
. J Q (alphanumeric) Pf . F
(literal) . PL M, F
F GA. PL :
226

PL (Integer Constant)

I O PL (Floating - point constant)

P PL (Character constant)

C-NJ M P F
FJ .

4.2.1.1 PL (Interger Constant)


PL F ( 10) .
F P . 0 9 J
. PL 0x 0X
A F ( 16) PL
. 0 A ( 8) PL .
Q F
.
23, 36, 48

A F (decimal)

0 x1C, 0XAB, 0x23


071,023, 035

PL

A F (hexadecimal) PL

A (octal) PL

PL N P
Q (Positive) . -18
PL. 2,345 PL,
. E C P (O)
.
4.2.1.2 I O PL (Floating Point Constant)
I O PL PJ (signed
. , F, F O
, H F, F A
. I O PL PH, F
O ( F) F
O F (HF)
. .
F J F O MM.
F, F H 10-
.
real number)

227

58.64 I O PL .
J :
5.864E1 => 5.864 X 101 => 58.64
5864E-2 => 5864 X 10-2 => 58.64
0.5864e2 => 0.5864 X 102 => 58.64
E e , I O PL
(exponent) M A.

4.2.1.3 P PL (Character Constant)


P (Character) K , ,
EP H C Pf A
A. PO F
EP J P F (Character Set) A.
FJ P P
P PL P. C-NJ
P HKO .

P: a,b,c,.........., z, A,B,C,...........,Z

P: 0 9

C P: +,-, * / % #

= , . ( ) [ ] ; : ?

:
1, a, +, -

A P PL .

P PL PH
P A. Q,
P P PL PH?
P P
.
P P PL PH
M K (escape sequence) . H
P
M K A.
\

P PL.
228

, M K F, C CM
P PH.
:
\a
\b
\f
\r
\n
\0

E (Beep)
HQO (Back Space)
(Form Feed)
F F (Carriage Return)
F K (New Line)
P (null character)

H P PL PH,
H (\\) .
4.2.1.4 G (String literal)
G PL , J P
FJ PO
P . Q (by default), P
(\0) GM F P .
PLJ F P
Q M M (\) .
G. GM
O K E, FJ
P 6 . P E
. GF F
. F c (length) 5
.
hello

4.2.2. P (Identifiers)
GL P (Variables), (functions),
M (data types), C (labels) A P
P A. PJ
, . H P
. PJ K W (underscore) .
. F 32
. , K (alphabet)
. . P :
229

x
length
x_value
y_value
a123

C-NJ C ( ) P
. W PJ
. .
123
P .
1abc
P .
x value
K O (space) .
x &y
M C P (&)
.
for
C-NJ C
4.2.3 M (Fundamental Data Types)
GF F
. EP k
,
A. C-NJ
.
int, float, char HK.
M Q M
A. C-NJ (pre-defined). C-GH (C-Compiler)
; P F O
F . M M
(primitive data types) .
MO P PM :
int x;
float f;
char ch;

int (Interger), float


, char P PA.

(real)

230

1 (int)
1.0 (float)
1 P PL (char constant)
1 G (string literal)
C-NJ (string) Q M .
Q G M char * (P
- character pointer) . P M, F
E (Arrays) P FJ .
F GF F 2 .
float F 4 , char F 1 .
int

4.2.3.1 M M (Derived Data Types)


long, double, unsigned E(Arrays), (Pointers) A
MOL M M .
long int L, double float- L M
. long int P PM :
long int i ;

long i;

F GF , 4 .
(real ) I L Q
double . GF 8
.
long

int 2
. F H F
H F . int
FH, F H ( H) (positive)
F (negative) P P (sign) H . int-
F - 32768 +32767 . unsigned int- F 0
65535 . unsigned long, unsigned char A
M .
unsigned int

231

4.2.3.2. P (Pointer Variables)


C-NJ P P (ordinary variables),
P (pointer variables) . P
F F .
:
int x;

, x , int F P;
F .
x = 10;

P PM :
int *y ;

PMH
y P. (int *).
P K F .
, P, , G
F H A. GF

H
K .
x P, y
P. x , y
. , x K y - .
y = &x;

P
. K (address of -&) P.
(indirection-*) P. P
(unary operators). PJ e .
P P FJ .
x , GF
. K W
A:
948
949

232

K 948
F . G
F K
. GF P F K P
K (address of - &) P .
x-

y = &x;

P, x- K y PJ F
. y P , K F
P. y, x- A .
A:
948

949

F 10 . x- F y PJ
(Q, y, x - A ?) .
, (indirection - *) P
. , *y , y- KJ F
F . , x- F 10,
P y, x - A Q, * y - F 10 .
x-

c GM
:
y, x
*y, x

PJ K (&x)
PJ F (x)

K (address of - &), (indirection -*) P


P GM .
4.2.4 P (Operators)
C-N P . P
GA. G
(operaton) PA Pf (symbol)
P (operator) . E
, KJ
233

P EP A. G
A K K K (order of precedence) A. (hierarchy)
. G F (I
I `) (associatirity),
A. C-NJ P :

P (Unary operators)

P (Binary operators)

P (Ternary operators)

4.2.4.1 P (Unary operators)


P K KJ GJ
. H (operand) .
EH F (associativity) I .
PO P E
4.1- :
4.1 P

Pf

++

I (increment)

--

(decrement)

(indirection)

&

K (address of)

F (logical NOT)

F
I

I, P PJ
FH ,
A. P P
A. , x int PJ K
P, &x A. , I,
P HJ (PJ)
H .
234

, I, H :

H (postfix) I

(prefix) I

A P HJ (PJ)
J, I
A.
H J, H I
H A.
P P F HFJ .
++, --

4.2.4.2 P Binary Operators)


W P (Arithmatic operators)

+, -, *, /, % A W P
H e P
A. W PO
4.2- . W PO
F I .
4.2 W P

Pf

(Addition)

N (Subtraction)

(Multiplication)

(Division)

eF (Modulus)

W P (int) I (float)
F . eF (modulus) P
FO . H eF
M . L
. H F E.
235

5 / 2 = 2 (H F E)
5 % 2 = 1 (H eF)
, P, H
M M . eF P, H
eF M . , , eF
P, N P
K .
* Pf, P
, PO P (
- indirection) A. * Pf

.

P:

4.2.4.3 d P (Relational Operators)


d L P
HO e P
A. MFM ! L
P (F P )
P . , HJ e
. 4.3- d PO
. d PO
F I
. , P
W J PJ I
.
4.3 d P

Pf

==
<
>
<=

G (equla to)
M CP (less than)
M K (greater than)
M CP G
(less than or equal to)

>=
!=

M K G

(greater than or equal to)


G (not equal to)

236

d P F ()
H M P A. M, K (True),
(False) A .
&&, || A
P, d
A. && P,
(logical AND) P . P,
A d K M J
K M .
M J M
. (logical OR) P FL .
A d
M J M .
K M J K
M. d P, W P
K . &&, || A
d P M K .
:

K M
. I FH.
d , && P
. && P FH
, d
FH.
.
(10<15) && (14<23)

(10<15) || (14<23) K M
. || P, d

A. MFJ, d
K Q, K .
d K ,
d FH.
Fd (Short Circuit Evaluation) .
(logical AND-&&) ,
Q,
. FH.

237

4.2.4.4 FH P (Assignment Operators)


FH P (=), HJ
F, HJ . C-NJ,
+=,
-=, *=, /=, %= A A-FH P
.
i=i+1;

. F, i PJ
FH I, I F, i- F F
A. P, A-FH
PJ M,
i +=1 ;

.
P, i- FH I F
F i- J += P
. , i *= 2 ; P, i - F
2- , F F i-J A.
PO, FH P I
K .
4.2.4.5 FH K (The order of evaluation)
PO K P MF
. PO K J
FH . ,
H P FH
.
5 * 2 + 8 + 3 ( 3 - 2 ) * 5
. , W
FH:
5 * 2 + 8 + 1 * 5
(P L FH)
10 + 8 + 5
23

(, M K A)
( H J F 23)
238

4.2.4.6 P

Ternary Operator)

C-NJ P . G
P (Conditional Operator) . P
Pf ? : .
H
. G PJ :
(G ) ? 1 : 2 ;
G K Q, 1 FH. G
Q, 2 FH.
:
j = ( i < 0 ) ? -i : i;

J G PJ
. i- F (absolute value) j- J
. i- F 0-M CPQ, j-J -i .
i- J F 0- G 0-M KQ j-
i- .
4.2.5 GP C
(Punctuations and Keywords):

C-NJ G P P
LA:
[ ] - EJ [index] P A
[ P ].
{ } - P F H A {O
P }.
( ) - PH, ,
A (
P).
< > - -L (preprocessor) P, H
A < P >
- G PH A (
).
- P PL PH A
( ).
239

/* */- P (Comment) .
;
- P P (O)
,
- HK A (O)
, O - GL O (read
ability) (Blank, white spaces) A.
A C O W .
GL PO .
auto
break
else
if
switch while

case
float

char
for

continue
int

default
return

do
static

C , L
L
. , auto
C . Auto, AUTO A
C .
4.3 FK C-G
MA M , C
O F G (Program)
A. F K GL CP E
A G (Function) .
C- G I CP . C-G
. C-NJ G
. , C-NJ
O
. C - GL P W :

#include <stdio.h>
main()
{
printf(Hello World);
}
C-NJ FK G

240

G A, Hello world F F
J . C-GL, main()
main() -
.
. F .
C-G , main()
A. , GL J A
. GL . F
, GL J M main( ) -
. , printf() - .
Of (F F) GL M
. F
H P ( ) .
main( ), . printf()
. Hello world G M W
.
#include <stdio.h> /* <= preprocessor statement */
main()
/* <= function header statement */
/* function definition starts <= comment statement */
{
function call statement
function body

printf(Hello World);
}

GL K #include <stdio.h> -L (Prepro. #include -L P .


-L , G N (compile time)
P MK
G.
# include <stdio.h> , stdio.h (standard input and output header
file)
H GL main() P
A. printf(), scanf()
-
k, Of O PM
stdio.h H .
cessor)

241

printf() , scanf()

A O PM,

int printf(char *, ...);


int scanf (char *, ...) ;

F.
E
J (variable numbers of parameters)
O(...) A.
(string) . ,
P
P. , C

.
, P
, P OJ H
PHA. GL printf( ) P
. , FF
.
char * ( ) , P (Character
pointer) A. P H .
C-N GH (Compiler), -
. , GL
O (Header Files)
PM. O
W GL :
#include <stdio.h>
#include <conio.h>
main()
{
clrscr();
printf(hello);
}

242

GL clrscr() -
P FK (PM) conio.h
H . , H
GL . # include <conio.h>
GL MQ, C-N G
H (Compiler), clrscr() P G
. Q, H PM.
4.3.1 (Statements)
C - GL K (Statement)
A. , .
-L (Preprocessor Statements)
(Function Header Statements)
PM (Declaration Statements)
(Executable Statements)
c P, -L, PH
OL O PM
, G MK E A.
, P J
K A. PM , P PM
(variable declaration statement), PM (function declaration statement) HK.
#include <stdio.h>
=> -L
main()
=>
{
int a,b,c;
=> P PM
int add(int,int);
=> PM
a = 10;
=>
}
O PM
P FJ M.
O . F
H (assignment statement) . P
J F A.
243

4.3.1.1 FH Assignment Statements)


FH :
P (Variable) = (Expression) ;
O A.
. P H . F
H, M . ,
F M. J
F, PJ A. =
P, FH P. PJ F
A. FH P (=)
A.

P, P
O P
A.
printf (hello) ;

(function call statement) .


, hello F FJ
. FJ A
E FH . printf() P
, F F
H K . ,
GL F :
int n ; /* P PM */
n = printf (hello) ; */ FH */
, n P (integer) PM
. FH , L
FH. H, F P
J . , FH P
, (function call expression) . , printf()
, hello F FJ . printf()
, 5 FJ 5 F
FH. J F. 5
F n PJ .
244

4.3.1.2 I,
(Increment and Decrement Statements)

PJ FH 1 F F
PJ F,
i =i+1;

A.

E, I
. :
i ++

(Increment Statement)

; /* H */

++i;/*

*/

, I P QG
O (stand-alone statements) F, H
I. i- F
I. i- FH ,
P .
i -- ; -- i;
I, P GO M
M . P H .
4.3.1.3 (Expression)
, FH P
. FH, F
M A. .
C:
int a,b,c;

/* P PM */

a =10 ;

/* FH

*/

P, 10 F
. PL (constant expression)
A. F 10.
b= a ;

F, P (variable expression)
. F 10. FH P
F . PJ F
245

J F. .
, J F PJ A
GM .
PO J
.
C W:

c=a+b;

c=a>b;

f=d =e;

FH

d , K (true)
(false) F. PJ .
1 0 F c PJ . =
P, FH P A.
, C-NJ FH A
. FH FA.

P, FH J F (, d-

F, FH J F) f
PJ A.
f = d =10;

. F FH
J F 10 . F d- A. H,
FH J F f- A.
4.3.1.4 H, I
(Postfix and Prefix Increment Expressions)

W G F :
int x, i;
i = 10;
x = i++; /*
printf(%d %d\n, x, i);

H I*/

P ++
e K . FH
P e K . H M,
L PJ F, J F
246

A. H, PJ F, IA. ,
F F . ,
J F; PJ F. FH
P J F 10. P x-
A. i- F 11 A.
FH
P PJ F ,
J F A
. , printf() P Of,
10 11

. W G F :
int x, i;
i = 10;
x = ++i;
/*
printf(%d %d\n, x, i);

I*/

M, L PJ F, I
, F F, J F A.
J F 11 P x-
A. Of,
11

11

. d
W :
nt x, z;
x = 100;
z = (x == x++);

H I
H d */
/*

printf(%d %d\n, z, x);

Of ?

FH P d
,
K , 1 0 F
. , z PJ F 1 0
. ++ PJ e K ,
d J H L FH
. H , J F
247

100 . H x- F I F 101
A. d J H
( P ) 101 F . ,
H F 101 100 . J G
. , z- 0 . Of,
0 101
.
FH P, J F
A . PJ F
.

GM :

4.3.1.5 k, Of :
(Input and Output Statements)

P, M Of
(FJ) H printf() A. FF
printf()
. J, printf() P
. Of (
) A.
(control string) A. , Of
FJ
(formatting string) .
:

F OJ:
int n ; /* P n PMA */
n = 10;
printf (%d ,n);

, %d P
P
F OJ,
. printf() P
, P .
P (Ordinary Characters)
P (Formatting Characters)
M K P (Escape Sequence Characters)
248
(formatting character) printf()

F P
. printf (hello); P
P . ,
FJ A. M
F FJ P
O 4.4- :

%d

int

%f

float

%c

char

%s

char [ ]

%ld

long int

%lf

long float or double

4.4

P, M K P
, H
. J P PL .
P IA,
A. Of M
K A. printf() P g
F A M K C:
\n \t

F K P

- P

\b -

H O P

W printf() :
int i =15;
printf (the value of i = &%d\n, i);

249

FJ Of:
the value of i = 15

printf() P, P,
P, M K P A
P . P
. %d P
M F FJ
. F K P \n , Of
K KJ, GA.
Of F KJ A.
printf (one\n two\n three\n) ;

,
one
two
three

FJ .
FK P
\n
Q KJ A.
W GL F :
int x;
float y;
x = 10;
y = 10.5;
printf(%d %f, x, y);

Of,
10
.

10.500000

I O F Q (by default)
LF . LF O
J MH,
% 0.2f
. F, F H L
A. ,
250

printf ( %0.2f , y);

P Of 10.50 . , Of
FJ ,
O
.
printf ( %10d %10.2f , x, y);

,
bbbbbbbb10bbbbb10.50 /* b

O PA */

MJL k (Input from keyboard)


M JL
( k) F
k scanf() A. scanf()- FK
(prototype), printf()- FK .
EJ .
P x- F M ,
int x ;
scanf (%d, &x);

P (code) A.
, K k
EP F. M M
Enter M F H,
O.
O GF x-K F A. scanf()
P &x . x
PJ G K PA. &
K P P. P
, PJ K PA.
scanf()

4.3.2  (User -defined Functions)


GL PH E e e
J, E GL O
G , E
P M, P
. G (Programmer) P
H E G
251

A , GL O
F . , , M
M ,
K
F A G .
A
(calling function) .
A
,
(called function) .
.
.
, H A
. , PH P P
H A. , PH E
, P
M HA.
P PM PM
C-NJ H C .
PM (function declaration) , P FK
(Function Prototype) FK (Function Model)
A. P
FK
:

FH FH M

O E

M M

, , M,
H - P
:
int add (int, int);

PM P add
P . A. int
. FJ int F FH.
A:
252

int add(int a, int b) /* function header statement */


{
return (a+b);
}
-

P FK PM
, O A. P
O F.
,
.
, K
O P { } .
O P P (code),
P F (body) F (block)
. P PM P
P (local variables) . P
P K.
P P.
, -
K N A.
add()

P G W :

253

#include <stdio.h>
#include <conio.h>
main()
{
int a, b,c;
int add(int, int);
a = 12;
b = 11;
c = add(a,b);
/* a b */
printf(%d\n, c);
}
int add(int x, int y) /* x y */
{
return(x+y);
}
P
(Actual Parameters) A.
P F
.
P

(Formal Parameters) A.
, O F
A.
GL,
c = add (a+b);

FH , GL
add() P A . a, b A
. , add( )
, H
F . F
P x, y A
A. add( ) ,
O F, O
254

, A.
F (call by value)
add( ) , M
A.
P FH A. C = add(a+b) P
. J
F, add() FH F.
A , GL ,
P, FL
FH.
GL , P
FH. A M F
. P PO F
A.
P P NA.
P PMA, A,
A P P A.
, add() , F
J A. F
J , FO
, P H
A. P FO
, P
P
O
F J FF.
P PO K
P FH, ,
P PO F P
. K (call by address)
E F .
:

W G :

255

#include <stdio.h>
main()
{
int i;
void change(int *);
i = 20;
change(&i);
printf(%d\n, i);
}
void change(int *x)
{
*x = 23;
}
GL Of 23 . ,
P
PJ F M.
change() P x, (in
teger pointer) . , P P i-
K A. x, i- A.
P, *x = 23; FH , x K
J F F A. x, i- , i- F
PMA.
, A G KJ F
, P * A
. W GF :
int i = 32;
int * p;
int m;
p = &i;
m = *p;

FH P *p, p-J
KJ F A. F, i
PJ F . *p ,
G KJ F
N F P . change()
256

P, P p- , P * (*p ),
FH P F. ,
P P,
J , G HF K
F FH . *x = 23; P ,
x KJ 23 A F A.
P, P( *),
F, M F ; F P
. F.
P, J, H
K
; F F P .
P c P
. W GF .
M . c PF.
int i = 10;
printf (%d %d, i, i++);

Of 10 10 10 11
c E i. GFJ

AA. C-NJ,
, I ,
F (Stack) A. -
M (Last - In- First - Out /LIFO) H .
H A
. J, H, e
AA. C
(CJ ) L . H
.
F :

257

%d %d
F C
11

10

printf() ,
F L F, i++ J F.
H , J F 10
F . H I PJ (++)
, i- F I, 11 . I
i . F
F . , 11 F L.
C , %d %d
F . Q
, printf() , F
CJL
. L OJ
%d %d.

. L %d , FL
(F 11) OJ .
%d-, F (F 10) OJ
F . L
AM. FJ,
11 10
Of . C-N
M KFd.
4.4 I (Storage Classes)
PJ J
(Name)
(Type)
F (Value)
258

I , P
. C-N A.
auto
static
register
extern

PJ
(scope and
bQ I A. auto
P J (local) P. PM
P GL
A. M O
NA. P P
P P . P
P MA.
, P
NA . PO
F P O .
, PO PM
P AMA. W G :

lifetime)

#include <stdio.h>
main()
{
add();
add();
}
add()
{
int i = 0;
i = i + 1;
printf(%d\n, i);
}
GL Of,
1
1
259

. i , add() P P.
add() , i P
F 0 F A.
M 1 . P static
PMH, H
F . add()
P W P :
add()
{
static int i = 0;
i = i + 1;
printf(d\n, i);
}

F, i P static PM.
add() P P. add()
. F
.
static P, L
A.
H P F
. static PO I K .
add()
i- F I Of,
1
2
.
GL, i P M (global)
P PM, P F . M
P main() P PMA.
P, GL ,
P.

260

#include <stdio.h>
int i = 0;
main()
{
add();
add();
}
add()
{
i = i + 1;
printf(%d\n,i);
}

GL Of :
1
2

GL, i M P.
P
. static P, PO H
. G H static
M PO A.
static PJ

PM .
M PJ , GL
M AA. M,
P O PM M P
static . , static P,
M P F .
register P, auto P A.
P register PMJ, F, E
PJ F F (registers) P F
A. G ,
register P A.

M P, G H
261

. M P PM
H O
JH, extern M PM
. , count M
P H PM, H
Q, H, P
,
extern int count ;

A PM . extern P M
. P , G
GF.
4.5 G  (Conditional Statements)
4.5.1 if
C-NJ G L
. if , G AHK
A. L K
Q d , K A F
M . C-NJ 0 , 0 F
K . G J F K
0 F if P FJ
G. if
:
1. if (d )
;
2. if (d )
-1;
else

-2 ;
M, d K (0 F)
Q, . J F
(0 F) Q, E.
M, else . J F
Q -2 G. O
262

GL , if H
MM.
if M C-G :
#include <stdio.h>
main()
{
int x;
printf(Enter an integer: );
scanf(%d, &x);
if (x > 0)
printf(The value is positive\n);
}

G, QI . if P G
0-M K K
F. KQ F FJ .
G AM. Of . GL
(x > 0) F
L A. C-N,
FH, F
bQA. L J F K Q, if
F ( if
F O P
O F) C-N G. L
Q, if F
O F C-N G MM.
:
#include <stdio.h>
main()
{ int x;
scanf(%d, &x);
if (x < 0)
printf(The value is egative\n);
else if (x == 0)
printf(The value is zero\n);
else
printf(The value is positive\n);
}

263

, if-else-if
. H (nested) if-else
. KO (choices) J C
G H if-else A.
EF O .
K K J , N, ,
A G. K F
J K M . G
NO :

O if F#include <stdio.h>
main()
{ int a,b,c,choice;
scanf(%d%d, &a,&b);

/*b N */

printf(1. addition\n);

/* 1 */

printf(2. subtraction\n);

/* 2 */

printf(3. multiplication\n);

/* 3 */

printf(4. division\n);
/* 4 */
scanf(%d, &choice);
if(choice == 1)
c = a + b;
if(choice == 2)
c = a - b;
if(choice == 3)
c = a * b;
if(choice == 4)
c = a / b;
printf(the result = %d\n, c);
}

G, KM J W
M FJ . K J,
GL d .
d A. (choice ==1) K
264

, H d J; MM
. Q H if-else
.

H if-else F#include <stdio.h>


main()
{
int a,b,c;
int choice;
printf(Enter two integers: );
scanf(%d%d, &a,&b);
/* b N */
printf(1. addition\n);
/* 1 */
printf(2. subtraction\n);
/* 2 */
printf(3. multiplication\n); /* 3 */
printf(4. division\n);
/* 4 */
printf(Enter your choice: );
scanf(%d, &choice);
if(choice == 1)
c = a + b;
else
if(choice == 2)
c = a - b;
else
if(choice == 3)
c = a * b;
else
if(choice == 4) /* H I */
c = a / b;
printf(the result = %d\n, c);
}

G, H if-else F.
G K Q, (choice == 1) K
Q, c = a + b ; G. else-
265

H M. , G
K H d
A; H d MA. G
, G d
. , G K .
G GM . K 4
Q, G d J
.
4.5.2 switch-case
C-N GL C GO CI H ifelse
switch-case P
. C G AHK
switch-case A. switch GL
FJ A. switchcase
P :
switch (G )
{
case

PL-1:
...............................
break ;

case

PL-2:
...............................

break ;
...............................
..............................
default :
....................................
}

P G PL
O M .
case- PL F, switch- G
F case GL
.
switch P case
. , switch case
PL . switch
P F G case
switch

266

P A, FJ F J
break F J case O
G. PH case P W
F GH GL switch-
F M O M break
. case P
F G.
case - PL F switch - G
F G Q, default
H F G. switch-
FJ default F , case P F
G J F M Q
switch- FJ P G
. default . Q P
H. FJ FJ
F. . O E
G H if-else F
F G, switch-case F :
#include <stdio.h>
main()
{ int a,b,c;
int choice;
printf(Enter two integers: );
scanf(%d%d, &a,&b);
/*b N */
printf(1. addition\n);
/* 1 */
printf(2. subtraction\n);
/* 2 */
printf(3. multiplication\n); /* 3 */
printf(4. division\n);
/* 4 */
printf(Enter your choice: );
scanf(%d, &choice);
switch(choice)
{
case 1:
c = a + b;
printf(%d, c);
break;
case 2:
c = a - b;
printf(%d, c);
break;

267

case 3:
c = a * b;
printf(%d, c);
break;
case 4:
c = a / b;
printf(%d, c);
break;
default:
printf(the choice is out of range\n);
}
G G (Modular) H . H if G K
O . , J (vowel),
(consonant) P
GF :
else

char ch;
ch = a;
switch(ch)
{
case a:
case e:
case i:
case o:
case u: printf(the given character is vowel);
break;
default: printf(the given character is consonant);
}
, ch PJ F a
case K A. F break
, G, case . break
. break F case
. F case u: . a,
268

, u , G u-
. K
G. given character is
vowel F FJ . , break
, G, switch M O.
J , default FK
G
. H G, O P M
O.
e, i, o

4.6 (Control Statements)


P G K Q, if - d
J F K Q, if- P F
G. C GO,
PH G K ,
F F F G
. G (control)
(looping) . (Loop)
GL F.
A e
F F G
O F. C-NJ
() . : while, for,do while A.
if

4.6.1 while
PH G K GJ ,
O F F F while
A. while P, F G
J G KA. (,
P

bQ). W G J
KO FJ . , printf( )
10 .

269

#include <stdio.h>
main()
{
int i;
i = 1;
/* FH */
while(i <= 10)
/*G */
{
printf(%d\n, i); /* */
i = i + 1;
/*H */
}
}
GL, i P P A.
while A G A. while
P PM,
FH. G,
,
1 PJ F 1
. , 10 G. G
i <= 10 . P G K
Q while A F 10 G.
G P
J F 1 IA. , K
G. G
Q, GL A M O M.
OPH, A F
JL, GL . e
G . PJ F
F while P KF
A. while (O
P ) PJ F, 1 IA.
while P :
/* P A */
while (G)
{
.................. ; /* */
.................. ;
P H ;
}
270

PJ F, while P G
H A. while A
P H.
i- F H.
i = i +1 ;

A K, M J, PJ F
1 . .
GL FH, G, H
printf (%d\n, i) ;
A cAM ,

IA. ,
GL GP A.
HP .
1, 2, 4, 7, 11, 16........ KJ 15
G F .
KJ ,
H A. ,
H A. ,
H A.
H
A. 15
G. G:
#include <stdio.h>
main()
{
int term;
int i;
i = 1;
/* P*/
term = 1;
/* P*/
while(term <=15)
{
printf(%d\n, i);
i = i + term;
term = term + 1;
}
}
271

GL, term P, A
. i P P
. GL (logic),
i=i+term . KJ
term - F A.
term- F 1 I
A. while A F GL P,
P
FA. PJ FH
; GJ KF , A
H . P P.
while P while H
. O
while O while M
. O while
while M. while
PO FH
. F F E
G .
A, P H.
:

G : 1 , KJ 2 ,
KJ 3 ... 10 FJ
. KJ 10 .
G . -
O bQ. ,
O-A PJ F ,
- F E .
G :

272

#include <stdio.h>
main()
{
int i, j;
i = 1;
while(i<=10)
{
j = 1;
while(j <= i)
{
printf(%d , i);
j++;
}
printf(\n);
i++;
}
}
GL Of :
1
2 2
3 3 3
...................
1 0 10 10 10 10 10 10 10 10 10
GL, - i
F A. i O-A
P.
4.6.2 for
C-NJ for , while P J
. , C-GL F
:
x=1;
while (x<=10)
{
printf(%d\n, x);
x++;
}

273

F for F W P
:
for(x=1; x<=10; x++)
{
printf(%d\n, x);
}
while A
FH (x=1), K
(x<=10), F I (x++) A G

.
F KJ
for A. for A,
GJ G KFA. for A
F 10 A. F, PJ L
F A. H F KF
A. G K Q, A F
A.
, ,
G A.
A F H, GL
e for
. P H.
, G KF. G K
F F .
for
for
{

A :
( F ; G; H)
A F ;

for P . 1 ,
2 , 3 , .......... G H for
F F :

274

#include <stdio.h>
main()
{
int i;
int j;
for(i=1;i<=10;i++)
{
for(j=0;j<=i;j++)
printf(%d , i);

-
Inner
Loop

printf(\n);
}

for A . O for
A . A FJ
J, A
F O P F.
F E for
F . A
A E L K
Q E for A C G
.
GJ
GO while .
while

275

#include <stdio.h>
main()
{
char ch;
int count = 0;
ch = getchar();
while(ch != \n)
{
}

/* G*/

count++;
ch = getchar();

printf(the number of characters entered: %d\n, count);


}
, MJ Enter
M . J,

E. ch P, F K P (\n) M
N ( Enter M F
), G .
GL while
A F printf()
M. E while . ,
k L E
. GL, M JL F
getchar()
. - .
4.6.3 do-while
A GJ G K
A. G A,
A F . do-while P,
O GJ G KA. ,
G K H, A
276
while

F . do-while
A FJ G
K, K Q e
. G K
. G ,
. GL , do-while
.
:
x = 14;
do
{
y = x + 2;
x;
} while (x > 0);

do-while P, x- F ,
y=x+2;
x -- ;

. H
x > 0 G FH. x, 0 -M K
H, A F e . H x > 0
G e FH. x- F 0-M
K A F e e
. x- F 0 , F (negative)
do-while P G. , dowhile A F
.

4.7 E (Arrays)
O M O
E A. E F
O G (programming) OA .
, O K P .
QQ P . O if
F G W :
277

#include <stdio.h>
main ()
{
int a, b, c;
int max;
printf(Enter the 3integers:);
scanf(%d %d %d,&a,&b,&c);
max = a;
if(b > max)
max = b;
if(c > max)
max = c;
printf (%d is the maximum ,max);
}
G, 100 O K P
c Q, 100 QQ P .
if- J.
G F C. I c. ,
K G N . C b O
N 100 E PM:

int a [100];

type

Array
name
E
array
name

Number of
number of
elements
O
elements

K 100 K
(index) . 100 F F
100 P C
A. E PM, EJ PHA;
O M KMA. P
PL .
O E PA. F
0-M K . EJ IH
EJ I
PA. EJ

278

H A C , GF
HO A.
C-NJ E (array) K
K . E
J . 10
K E PM.
int a[10]

/*

E PM */

G , GH (Compiler)
KJ 10 F G
F 20 A.
G . 10
G O A. E
J 0- . EJ n
J 0- A n-1
. E O
W FH
A.
a [0] = 10;
a[1] = 20 ;
...................
a[9] = 100;

EJ E P C F Q,
A .
, W GF, EJ O K
F A.
int i;
int a[10];
for(i=0;i<10;i++)
scanf(%d, &a[i]);

scanf() P &a[i]
, i = 0 9 GJ i- H
K A. scanf() MJL F
279

H , GF K F (KJ) F
A.
EJ FH.
int a[3] = {10,15,20} ;

EJ GF :
948

950

952

10

15

20

O F

a[0]

a[1]

a[2]

2 G
A. GH (Compiler) C
A A. G F
(block of memory)
A. FJ K F
948. a[0], a[1], a[2] A O K 948, 950,
952 .
H K &a[0] PHA.
K 948 . KJ FA
F 10. a[0] , H F
. , a[0] - F 10, K 948
. GH, EK G
F W H, FJ
K (948), EJ K FA. ,
a, &a[0] A EJ K PA
. EJ a, E A .
, a, K A .
J Q, a, EJ H A
.
a

948

950

952

10

15

20

a[0]

a[1]

a[2]

P P
F G F F .
, *a 10 F . ,
280

a[0]

*a
*(&a[0])
A 10 A F
P. ,
a[0]

*a *(&a[0])

. , Pf, J
A. Pf
C-N P .
MOL, EJ K
( K) EJ K A
K d. EJ ,
K (pointer) A.
, EJ H A. E
J
, KJ K
F . EJ
K (base address) P . , EJ
P
. EJ K K P
PL (pointer constant) A.
E
. x P .
int *x;

MA,
E .
int a[3] = {10, 15, 20};

F x P (pointer variable). int


, int PJ K .
a , int F . , EJ
H PL (pointer constant) EJ
K x PJ F .
281

x=a;

, x P, EJ K
. x ()
P (variable) , G A
F P, EJ H
. W (pointer arithmatic)
C-NJ C .

W G

FH , N
.

O FO N .
W M :
x
a

948

950

952

10

15

20

a[0]

a[1]

a[2]

P , x, a A EJ
. , x, a 948
K A. 0- , x, a
AP K FO M .
P * F KJ FH
. , *(a+0), * (x+0) A 10
F A. *(a+0) , E
J H F P (notation)
. EJ H F a[0]
E P P. W
G :
x = a

x+0

*( x + 0 )

*( a + 0 )

*( a + 0 ),

a[0]

a+0

A ,

* (x+0) x[0]
282

. F, x P 0
W (subscript) (index) ,
EJ A.
K (a pointer can be idexed)
P. , C G
F F. x+0
H K. * (x+0) KJ
H F. EJ a P
x- 1- , H K A.
a+1

x+1

, KJ A. ,
W , W . A
MF GM . WO,
MF J i .
x, int F A. int 2
. i E (scale factor) 2 . ,
x+1 948 + 1 * 2 = 950
a+1 948 + 1 * 2 = 950 &a[ 1 ]
.............................
.............................
a+i

&a[ i ] x + i

&x[ i ]

a+i EJ i- H K PA.
*(a+i), i- H F PA.

MOL c K
:

E .

, E M .

10 EK F M
JL G :
283

#include <stdio.h>
main()
{
int i;
int a[10];
for(i=0;i<10;i++)
scanf(%d, a+i);
}

P, &a[i] F a + i
. ,
G GM. i = 0
, a + i H K
A. i = 1 , H K
A. , a + i K
A.
scanf()

J E,
.
P E . 24 (
GO P PA)
E PM.
char name [24];

F, name 24 E.
GF C 24 .
K EJ name- . (string) ,
P (null character - \0) O
. , ,
O E A. MJL
,
scanf (%s, name);

A.
F, %s
. %s, F L
O (blank space) P (delimiting character) F. , M O
.
284

, K k F.
O name
\0
KJ A, K . FJ
P . F
J ,
printf (%s, name);

P .
P %s, name
K A, P
C .
, O F ( E)
M char * . PL (string constant)
M (char *) , F K
, F F
. , PLJ F,
G FJ K.
W G F :
if(rama == rama)
printf(equal);
else
printf(not equal);

F, H PL H G P
H. C-N GH
(Compiler) . GF not
equal M . F, FK
H, GF
O .
PLJ F, F K, F
P P.
, d, G F K
H. . ,
GF not equal Of A.
PH F E
G . string.h ,
285

A.
A.
F c P strlen()
strlen() - . FK
string.h H PM. strlen() P FK
:
int strlen (char * );
strlen() , , c
FH .
#include <stdio.h>
#include <string.h>
main()
{
char name[24];
int len;
printf(enter a string: );
scanf(%s, name);
len = strlen(name);
printf(%d\n, len);
}

G MJL ,
c P M FJ .
P, E H
J, F . F
c P, P F .
W PJ, lenstr() , -
(user-defined function) .
- 1:
int lenstr(char *s)
{
int count = 0;
while(s[count] != \0)
count++;
return(count);
}
rama lenstr() P
H, P (s)
. P (character pointer) .
286

, s rama .
while count = 0-L A , s[0]
F
P GA. r
PA. P . while P G
K A. , while A F A. count - F IA.
s[count] == \0
,
. FJ
count- F FH . , F
O E .
-2

int lenstr(char *s)


{

int count = 0;
while(*s != \0)
{
}

count++;
s++;

return(count);

GL A , *s- ,
F r . while
A FJ, , I,
F . *s, \0
.
rama

- 3

int lenstr(char *s)


{
char *start, *end;
start = end = s;
while(*end)
end++;
return(end start);
}

287

, start, end, s A
P rama
. rama H
A .
lenstr()

A, F F KA
948- A. end \0 F
while A F. ,
, end 952 K .
while P G . F * end - r
F . 0
G K
. * end - \0 F , 0
G AMA. while
, end 952 K .
start 948
K .
end-start (952-948) 4 M .
F F O E
FH . L N
, O
E M A. E
, W FA
F .
start, end, s

4.7.1 K E (Multi dimensional Arrays)


C-NJ K E , EO E
A. K E PMA:
int a[3][3];

PM, 3x3 E
(matrix) AA.
F 9 . GH, EJ
F, C 18 A
A. K, AO (rows) E
288

PA. K O (columns)
E PA. E (K)
F , K .
A (Row Index),

(Column Index). C-NJ E 0-M
A.
a[0][0]
. W G
F :
int a[3[[3];
int i;
int j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf(%d, &a[i][j]);

GF, E K F A
K A. O for A i = 0 ,
- j = 0, 1, 2 A F
A. , AJ A.
, i = 1, i = 2 A F -
A. F O, A
O() M
C O.
EJ A .
A E PA.
, EO E M . K
.
E PA. Q K
3 .
W E :

1
4
7

2
5
8

3
6
9

, EO E, PH:
289

a[0]
a[1]
a[2]

{1, 2. 3}
{4, 5, 6}
{7, 8, 9}

K 3 E.
E.
(integer pointer) . , int a[3] [3] P
M M . K 3
E. K
3 E.
K
3 A
A; . J a[0][0]
E J . ,
AJ . a[1]
A A. C-N GH,
K E J A.
K A, K
PA FA.
3x3 K EK F
P. , EJ
A K FJ GF F
.
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
printf(%d , a[i][j]);
printf(\n);
}
3x3 K E
M
EJ , E
(matrix Addition) G W :

290

 #include <stdio.h>
#include <conio.h>
main()
{
int a[3][3], b[3][3], c[3][3];
int i, j;
/* read values for the input matrix a */
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf(%d, &a[i][j]);
/* read values for the input matrix b */
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf(%d, &b[i][j]);
/* initialize the output matrix c with all elements 0 */
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j] = 0;
/* add matrix a and b and store the result in matrix c */
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j] = a[i][j] + b[i][j];
/* print the resultant matrix c */
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf(%d , c[i][j]);
printf(\n);
}
}


291

GL F K
M (comments)
. EJ A QQ
M G W . G,
3x3 K EJ A
J O F (maximum value)
PA.
#include <stdio.h>
#include <conio.h>
main()
{

int a[3][3], max[3];


int maximum(int *); /* declaration of user-defined function */
int i, j;
clrscr();

/* to clear the contents of the screen */

/* read values for the input matrix a */


for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf(%d, &a[i][j]);
/* find the maximum in each row and store in the array max */
for(i = 0; i < 3; i++)
max[i] = maximum(a[i]);
/* print the max array */
for(i =0; i < 3; i++)
printf(The maximum value of row %d = %d\n, i+1,
max[i] );
}
int maximum(int *x)
{

int mvalue;
mvalue = x[0];
for(i = 1; i < 3; i++)
if(x[i] > mvalue)
mvalue = x[i];
return(mvalue);

292

GL, 3 EJ
F P -
. P maximum() . , int *
.
F FH
. F. main()
P, for A 3 A.
maximum() ,

A H
A. a[i], i =0,1,2 A A .
P,
x
M, AJ K
A. P, x K
( 3 K A )
. N EJ .
AJ F, mx E
J FA. , EJ
A K
F QQ P.

4.8 (Structures)
C-NJ (structure) M
. H M P
A. ( P
J). - M
A. , HQ I
(record) A.
O . O
(fields of information) .
(derived data type)

- W :
K , ,
O F,
1001, , 18
.
P
293

. K

1001, 18 .


M O .
M O . E
(homegeneous) O .
(hetrogeneous) O .

M :
K

: O E

struct student
{
int rollno;
char name[24];
int age;
};

C-NJ C .
A. student P
(structure tag) (tag name) A.
, P,
, M
M KMA. M
(template) A.
(skeleton) . J, O
P PM P ()
M (members).
Q (unique) .
O . GF
W . ,
G F . ,
O FH .
294
struct

, M struct student
. , struct student - F
M AM. F M
A. MF, P PM . H
P P PM .
:
struct student x, y;
x, y A struct student P. P
M .
struct student P 28
A.

M (global
entity) . , GL
A.
P M P PM
. ,
struct student
{
int rollno;
char name[24];
int age;
} x, y ;

F, P P
M. (tag name)

.
P PMM.
, - M
.
295

:
struct
{
int empno;
float salary;
} x, y ;

J
J, x,y M F P
. ,
, .
W
:
struct
{
int empno;
float salary ;
};

4.8.1 M
(Accessing the members of the structure)

M () , O
P (dot operator) A. O P
M , P F
(Qualifier) A. , K
K , , P
x , rollno
, P:
x.rollno

O FH; O F P
. x, y O rollno F FH
:
x.rollno = 1000;
y.rollno = 1001;

296

F scanf()
:
student

scanf (%d %s %d, &x.rollno, x.name, &x.age);


student
M name , 24
KJ K PA
. , scanf() P, x-
x.name PH . O
& P F, &x.name
J F .

4.8.2 (Pointers to Structures)


M

PM . ,
struct student *ptr;

PM P, ptr - M
struct student - A .
PJ
K ptr-
.
:
struct student s1;
ptr = &s1 ;

/* ptr

s1- A */

ptr , s1- , O
P F P (->) .

, rollno ptr->rollno
. (*ptr).rollno .
4.8.3 O E (An array of structures)
O E PM:
struct student x[5] ;

F, x ,
O E. x[0],
x[1], .....x[4] A, struct student M QQ
. P ,
:
297

x[0].rollno, x[0].name, x[0].age

EJ H F
,
scanf (%d %s %d,& x [1] -rollno, x [1].name, &x [1].age);

5 O K M , for
A .
for (i=0; i<5; i++)
scanf (%d %s %d, &x[i].rollno, x[i].name, &x[i].age);

, O H F
J for A .
K K, K K I
. QQ P K .
M ,
A.

JC M
I. K PH

1.

G
.

2.

L PM O.

3.

bP (Algorithm) EJ
G .

4.

GJF L (Indefinite Iteration)


P (Index variable) A.

5.

GJF L G
KA.

298

II OJ G

1.

G
A.

_________

2.

L P K ,
K M _________.

3.

G A
_________.

4.

K (walkthrough) H
H P _________ .

5.

b PJ (Algorithm) G
_________ M _________, _________
.

III. F

1.

L P
.

2.

F
. P
M.

3.

N AHK .
L P F .

4.

N AHK .
.

5.

P M.

6.

GJ
M.

7.

GF
M

8.

GJ, GF
PH.
299

9.

N AHKM N AHK I
M
.

10. L P
M.
11.

bP (Algorithm) J ?

IV. G JC: G,

, L P .
1.

FF 5 C-G

2.

PO F C-G

3.

W E C-G :
(i)

F P

(ii)

G qL C

E: GI: M
MO
4 . O K P C-G

(i) if F
(ii) if
[MP : max =((a+b)+abs(a-b)/2]
(iii)

5.

FJ ,
, A C-G
. (O F 30
).

6.


O P
1+2+3+..... +10 P C-G .

7.

C KJ (Fibonacci series) 15
P C-G .
300

8.

K J E
C-G

9.

e
E (greatest common factor) P
C-G .
(MP: e... P W P :
int gcf(int first, int second)
{

int temp;
while(second > 0)
{
temp = first % second;
first = second;
second = temp;
}
return (first);

10. gcf() F, H
C - G . 16/64
k 1/4 Of .
11.

3025 E F (30),
F (25) , (Square)
A (3025) M A.
(30+25)2 = 3025.
P C-G .

12 . : E
(square) FH ,
FH E
G. , 12 .
122 =144. 12 FH 21. 212 = 441 (144
FH A) ! 10 100
P C-G .
301

13. , C KJ
KF C-G .
14. CP F (lower case) K
F (upper case) , K CP
F C-G .
15. F (Decimal Number)
(binary), (octal), F (hexa decimal)
C-G .
16. F C-G
17. G (perfect) , M
H O (divisions) G
. 6 G . , 6 M H
O 1+2+3=6. 1 10000
G P C-G .
18. IG (abundant) , M
H O M CP
. 12 IG . 1 2 M ,
H O (1+2+3+4+6=16) 12 M
K. 1 10000 IG
P C-G .
19. (deficient) , M H
O M K . 9
. 9 M H
O (1+3), 9 MCP. 1
10000 P C-G
.
2 0 . F H (reverse) CG . k rama Q Of
amar .
2 1 . L (H
F - MM, malayalam)
P C-G .
302

2 2 . KJ 10 K
J C-G .
2 3 . F O F
P C-G .
2 4 . 10 O K P C-G .
25. a E n .
F .
E
KF, KP H
PH H F .
K FH F .
2 6 . E J (Matrix) M (diagonal)
O P C-G .
2 7 . EJ E (Transpose)
C-G .
2 8 . E (Matrix Multiplication) M
C-G .
2 9 . E J
J , C F P C-G
. , C F P
.
(integer pointer) . (M
P:
E P
H . J
L KJ F,
P H).
30. 10 EJ I ,
KJ , C-G .

303

You might also like