Sie sind auf Seite 1von 98

- 1 -

C Language Introduction
Languages :
A Set Of Statements Is Called A Language.There Are Four Types Of Languages According To Their Time.
I generation languages: these languages are machine languages. To write programs in these languages the
system technology must be required. The data is
Non-portable. That means a program written in a system does not work in
another systems.
Ii Generation Languages :These Are Assembly Languages. These Are Also system oriented that means to write
any program in a system that systems technology must be required and data is non-portable. But they used
MNM!N"# words in programs. That means they used a single word instead o$ more words.
III Generation Languages :In these languages programs are witten in
general english language.There is no need to know the system technology and the
data can be transfered anywhere.
IV Generation languages :These languages are defined in any one of the
above languages.These are also called as packages.
Here I & II Generation languages are called ow evel anguages and III & I!
generation languages are called High evel anguages.
"or high level languages we have to use translaters to translate the source code
written in general english language into machine language. These translaters are
two types.
1% "nterpreters& '% #ompilers.
1 Interpreters :These translaters translate the source code step by step into machine language until any error.
"$ there is any error it stops and shows some message. A$ter correction it can continue.
!": BA("#& )Base """*& ....
# Compilers :These translaters translate the entire source code into machine language when it is error-$ree
and creates an ob+ect $ile in machine
language. "$ there is any error it shows the list o$ error. A$ter debugging it creates the ob+ect $ile.
!": #!B!L& #& #**& ...
- ' -
C LA$G%AG!
The language ,# was designed by &ennis 'itchie at AT - T Bell Laboratories. The standardised # was released in
1./..
The ( C) l anguage i s us e d t o de *e l op
i% (cienti$ic applications&
ii% Business applications&
iii% 0raphical applications 123 4"N)!4( %&
i5% (ystem programs&
5% !perating (ystems 123 6N"7% & ...
Character Set :
alphabets constants& statements&
digits 889 5ariables& 889 889 :rograms
special symbols ;eywords instructions

Constants : The unchangeable quantities are called #onstants.The constants are generally two types.
1% #haracter constants 3
a% #haracters 23 ,a& ,<& ,*& , ,& ...
b% (trings 23 =abc>& =?@<>& ,rama>& ...
'% Numeric #onstants 3
a% integers 23 ?@<& -A</& A<<@<& -@'/AB&...
b% Ceal numbers
i% Dractional $orm 23 ?@<.A/& @?<.EEE<?& ...
ii% 2ponential $orm 23 E.E'e@& 1.1/e-@B& ...
+aria,les : The quantities which can be changed during the e2ecution o$ program are called Fariables. A 5ariable can
be considered as the name o$ the cell which can hold the constants. To use any 5ariable it must be declared with its data
type be$ore the $irst e2ecutable statement and they can be initialised. Naming the 5ariable is 5ery important.
1% The 5ariable name must be start with either alphabets or an underscore and may contain alphabets& digits&
hyphen or underscore.
'% The ma2imum length o$ a 5ariable is B characters. But some compilers can accept upto @' characters.
@% There must not be any blan; spaces or special symbols in a 5ariable name.
?% A 5ariable name must not be a ;eyword.
23 valid invlid
eno emp name
empname emp1name
emp-name ?<abc
-ey.ords : These are prede$ined words. There are @' ;eywords in # language. These ;eywords can not be used as
user-de$ined 5ariables.
Operators : There are ?' operators in # language.
- @ -
1) Arithmetic Operators : + - * / %
23
1EE * ?E 889 1?E
1EE - ?E 889 AE
1EE G ?E 889 ?EEE
1EE H ?E 889 '
1EE I ?E 889 'E
?E I 1EE 889 ?E
# Assigning Operators : =
15ariable% 8 1constant% H 15ariable% H 1e2pression% J
23 a 8 <
b 8 a
c 8 a * b -'
/ 0ultiple operators : += -= *= /= %=
23
a 8 a * @ 889 a *8 @
a 8 a - @ 889 a -8 @
a 8 a G @ 889 a G8 @
a 8 a H @ 889 a H8 @
a 8 a I @ 889 a I8 @
1 %nary Operators : 22 33
2 3
a 8 a * 1 889 a *8 1 889 a ** 889 ** a
a 8 a - 1 889 a -8 1 889 a -- 889 -- a
4 'elational Operators : == > < >= <= !=
5 Logical Operators : && KK L
6
& . 3 J M 9 N O P 1 % Q R ......
Structure of a (C) program :
preprocessor commands
global declarations
main1%
#
local declarations J
statements J
- ? -
$
$unction1arguments%
#
local declarations J
statements J
$
The ,# program has a $ree $ormated structure.
5ery statement must be terminated with a semicolon J
A program is a collection o$ $unctions. There may be a lot o$ $unctions but at least one $unction must be there that
is main1%& where the e2ecution starts.
# has case sensiti5ity. All the ;eywords are de$ined in lower case.
(o better to write entire program in lower case.
:reprocessor commands 3
The commands which start with a hash1N% symbol are called :reprocessor commands.
2 3
N include Mstdio.h9
N include =conio.h>
N de$ine :" @.1?1<.
0lobal declarations 3
To use any 5ariable it must be declared with its data type be$ore the $irst e2ecutable statement. The 5ariables which
declared in a bloc; are a5ailable in that bloc; only.
To use the 5ariable in the entire program with same e$$ect it must be declared as global.
- < -
)ata Types 3
Type Range occupied bytes format string
signed char -%&' to %&( % )c
unsigned char * to &++ % )c
shortsigned int -,&(-' to ,&(-( & )i )d )o ).
short unsigned int * to -++,+ & )u
long signed int -&/,% to &/,% -% 0 )ld
long unsigned int * to &/,& -% 0 )lu
float ,.%0e-,' to ,.%0e,' 0 )f )e
double %.%(e-,*' to %.%(e,*' ' )lf
long double %.%(e-01,& to%.%(e01,& %* )f
Functions :The $unctions are two types.
1% deri5ed $unctions& '% user-de$ined $unctions.
The deri5ed $unctions are de$ined by the ,# authors. They de$ined them in the header $iles. To use the $unction the
header $ile must be included as preprocessor statement.
1% clrscr1% 3-
This $unction is used to clear the screen. This $unctions prototype has de$ined in the header $ile #!N"!.S
1 #!N"! 889 #onsole "nput !utput %
(ynta2 3
clrscr1%J
'% print$1% 3-
This function is used to display the te.t and the values of
variables. This function2s prototype has defined in the header
file 3T4I5.H To display the variable2s value the format string
must be used.
6 3T4I5 778 3tandard Input 5utput 9
(ynta2 3
print$1= $ormat string =& 5ariables% J
2 3
print$1= Sello Tt 4orld =%J
print$1= Id Ic>& ;& +%J
print$1=The mar;s are Id& Id& Id>& m1& m'& m@ %J
$ote : The $unction print$1% returns an integer 5alue that is the number o$ arguments gi5en to the statement.

- A -
'emar7s :To write any remar;s or comments to the statements they must be enclosed with the symbols HG GH
!" :
:;
sd$+;shad+$sd+;a$;+sad+;$h;asd+
sda$hasd$hgasdh$gasdg$gasd$hasd$+
sda$+;sad$+asd;h$+asdh;$+h;sda
;:
!" 8rograms :
1 9: 0y First (C) 8rogram :9
N include Mstdio.h9
N include Mconio.h9
main;
{
clrscr1% J
print$1=Sello> %J
printf;<=hanodaya < >
printf;<?elcome < >
}
:;
(a5e this program 1D'% as D"C(T.#
A$ter compilation1Alt-D.% it creates an ob+ect $ile& and an e2ecutable
$ile which can be e2ecuted at M(-)!( prompt.
By sa5ing a modi$ied $ile it creates a bac;up $ile.
D"C(T.#
D"C(T.BAU
D"C(T.!BV
D"C(T.7
!utput 3
Sello Bhanodaya 4elcome
;:
- / -
T6CB! # editor 3
"t is a compiler o$ # program and it can be also used as an general editor. To enter into editor $irst change into the
directory which contains the so$tware and enter the command T# at the command prompt.
#3T9 #) T#
#3TT#9 tc
Then it opens the editor which contains a menu bar at the top& a status bar at the bottom and a main window to write the
programming statements and a sub window which shows the messages.
The menu bar contains some menu pads and they can be selected by pressing ALT and the highlighted character in the
required menu pad.
Then it shows the submenu which contains some bars and they can be selected using arrow ;eys.
The status bar shows online help and the ;eys in$ormation.
1% To write a new program select ,New command $rom =Dile> menu.
'% To sa5e the wor;ing program select ,(a5e command $rom =Dile> menu
or press D' and enter a name.
@% To compile the program select ,#ompile to !BV command $rom =compile> menu or press Alt * D.. Then it
shows the list o$
errors or warnings. "$ the program is error-$ree then the compiler
creates an ob+ect $ile 1.!BV% and an e2ecutable $ile 1.7%.
?% To e2ecute the program select ,Cun command $rom =Cun> menu or press #trl * D..
<% To seee the output o$ the e2ecution select ,6ser (creen command $rom =Cun> menu or press Alt * D<.
A% To close the editor select ,Wuit command $rom =Dile> menu or press Alt * 7.

- B -
scape (equences 3
<* 778 Null character
<t 778 Tab 6 ' spaces9
<l 778 ine feed
<r 778 =arriage >eturn
<n 778 New line character 6 <n 7 <l ? <r 9
<a 778 @lert 6beep sound9
<2 778 3ingle Auotes
<B 778 4ouble Auotes
<< 778 back slash
!" 8rograms :
2) ! "sing #scape Se$uences !
% include &stdio'h(
% include &conio'h(
main))
*
clrscr)) +
printf),-ello .t ,) +
printf),"daya .n/) +
printf),0elcome ,) +
1
:; 5utput C
Hello Ddaya
Eelcome
;:
/
N include Mstdio.h9
N include Mconio.h9
main;
*
clrscr; >
printf;<@ello At =hanu An ?elcome < >
1
:; 5utput C
Hello Fhanu
Eelcome
;:
- . -
1 9: %sing +aria,les :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int ; 8 A< J
char + 8 ,G J
clrscr1% J
printf;<An The *alue of 7 is Bi Bd Bc Bo B"CD 7D 7D 7D 7D 7 >
printf;<An The *alue of E is Bi Bd Bc Bo B"CD ED ED ED ED E >
1
HG !utput 3
The 5alue o$ ; is A< A< A 1E1 ?'
The value of G is 0& 0& ; +& &a ;:
2) ! 3ormatting the output !
% include &stdio'h(
% include &conio'h(
main))
*
int a4 b4 c +
clrscr)) +
a 5 6 + b 5 27826+ c 5 69: +
print$1=Tn IE<d Tt Id>& a& a % J
print$1=Tn IE<d Tt Id>& b& b % J
print$1=Tn I<d Tt Id>& c& c % J
1
HG !utput 3
****- -
&,0+- &,0+-
-(' -('
;:
6) ! ;rithmetic <perations !
% include &stdio'h(
% include &conio'h(
main))
*
int a4 b4 c4 d4 e4 f +
clrscr)) +
a 5 =>> + b 5 8> +
- 1E -
c 5 a ? b +
d 5 a @ b +
e 5 a ! b +
f 5 a b +
printf),The giAen Aalues are Bd4 Bd/4 a4 b ) +
printf),.n The addition is Bd/4 c) +
printf),.n The subtraction Bd/4 d) +
printf),.n The product is Bd/4 e) +
printf),.n The diAision Bd/4 f) +
printf),.n The reminder is Bd/4 aBb) +
1
:; 5utput C
The given values are %**H 0*
The addition is %0*
The subtraction -*
The product is 0***
The division &
The reminder is &*
;:
$otes : The Arithmetic operations are three types depend on the types o$ the operands in the e2pression.
operand% operand& result
integer integer integer
integer real real
real real real
!" 8rograms :
9) ! Type casting !
% include &stdio'h(
% include &conio'h(
main))
*
int m=4 m24 m74 tot+
float aAg +
clrscr)) +
m= 5 62+ m2 5 66+ m7 5 6:+
tot 5 m= ? m2 ? m7 +
! aAg 5 tot 7'> + !
a*g F ;float tot 9 / >
printf;<The three su,Eects mar7s are BdD BdD BdCD m1D m#D m/ > printf;<An The total Bd At A*erage
BfCD totD a*g >
1
HG !utput 3
The three sub+ects mar;s are A<& AA& AB
The total %11 @verage --.,, ;:
- 11 -
:) ! 3ormatting the output of floating point Aalues !
% include &stdio'h(
% include &conio'h(
main))
*
float bas4 da4 hra4 pf4 net +
clrscr)) +
bas 5 2>>>+
da 5 bas ! 2> =>> +
hra 5 bas ! 7> =>> +
pf 5 bas ! 2 =>> +
net 5 bas ? da ? hra @ pf +
printf),The Casic Salary Bf/4 bas) +
printf),.n Da B'=f .t -ra B>=>'7f .t Ef B2'>f/4 da4 hra4 pf) +
printf),.n Fet Salary B=>'2f/4 net) +
1
:; 5utput C
The Fasic 3alary +***.******
4a %***.* Hra **%+**.*** If **&+*
Net (alary /'<E.EE
;:
$) ! Erogram to demonstrate the Increment Decrement operators
!
% include &stdio'h(
% include &conio'h(
main))
*
int 7 F 4 >
clrscr)) + 5utput
+
printf;<An BdCD 7 >
G ?? + (
printf),.n Bd/4 ??G) + (
printf),.n Bd/4 G??)+ '
printf;<An BdCD 7 >
G @@ + (
printf),.n Bd/4 G@@) + +
printf;<An BdCD 337 >
7 F 227 2 227 2 227 > #1 printf;<An BdCD 7 >
7 F 4 >
- 1' -
7 F 722 2 227 2 227 2 722 2 722 >
printf;<An BdCD 7 > /G
getch; >
1
Notes 3
scanf; :
This $unction is used to accept the 5alues $or the 5ariables while e2ecuting the program $rom ;eyboard. This $unctions
prototype has de$ined in the header $ile (T)"!.S
The $unction print$1% returns an integer 5alue that is the number o$ arguments gi5en to the statement.
(ynta23
scan$1=$ormatstring> & -15ariables% %J
Note 3
To accept two or more 5alues with a single scan$1% they can be seperated by space or tab or enter ;ey.
2 3
i% int aJ
scan$1=Id>& -a%J
ii% int m1& m'& m@J
scan$1=IdIdId>& -m1& -m'& -m@%J
iii% char chJ
scan$1=Ic>& -ch%J
getch; :
This $unction is used to accept a single character $or the 5ariable while e2ecuting the program. But this $unction does
not display the entered character. This $unctions prototype has de$ined in the header $ile #!N"!.S
Note 3 To see the entered character the $unction getche1% can be 6sed.
(ynta23
15ariable% 8 getch1% J
2 3
char cJ
c 8 getch1%J
- 1@ -
!" 8rograms :
.% HG :rogram to demonstrate the di$$erence between the $unctions
scanf))4 getche))4 getch)) !
N include Mstdio.h9
N include Mconio.h9
main;
*
char ; J
clrscr1%J
printf;<!nter any character < >
scanf;<BcCD H7 >
printf;<Iou entered the character BcCD 7 >
printf;<AnAn !nter any character < > 7 F getche;> printf;<An Iou entered the character BcCD 7 >
printf;<AnAn !nter any character < > 7 F getch; > printf;<An Iou entered the character BcCD 7 >
getch;>
1
HG !utput 3
nter any character abcde$
Xou entered the chracter a
nter any character g
Xou entered the chracter g
nter any character
Xou entered the chracter d GH
1J 9: ?rite a program to calculate the totalD a*erage of a student)s three su,Eects mar7s :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int m1& m'& m@& totJ
$loat a5g J
clrscr1% J
printf;<!nter three su,Eects mar7s AnC >
scanf;<BdBdBdCD Hm1D Hm#D Hm/ >
tot 8 m1 * m' * m@ J
HG a5g 8 tot H @.E J GH
a*g F ;float tot 9 / >
- 1? -
printf;<The three su,Eects mar7s are BdD BdD BdCD m1D m#D m/ > printf;<An The total Bd At A*erage
BfCD totD a*g >
1
HG !utput 3
nter three sub+ects mar;s
A< AA AB
The three sub+ects mar;s are A<& AA& AB
The total 1.. A5erage AA.@@ GH
11 9: ?rite a program to accept an employee)s ,asic salaryD calculate daD hraD pfD net salary and print all
:9
$otes :
Conditional Statements :
"n # language the conditional statement returns Yero when the
condition is $alse. !therwise it returns a non-Yero11% 5alue when
the condition is true.
2 :rogram 3
1#
N include Mstdio.h9
N include Mconio.h9
main;
O output
int ; 8 < J
clrscr1% J
printf),.n Bd/4 G )+ +
printf),.n Bd/4 G&=>) + %
printf),.n Bd/4 G(=>) + *
printf),.n Bd/4 G?)G552) )+ -
printf),.n Bd/4 G5=>) + %*
getch; >
1
- 1< -
Notes 3
There are three types o$ conditional statements in ,#.
1% i$& '% switch& @% conditional operators
1% i$ ... else 3
(ynta2 3
if 6condition9 if 6condition9
# #
6statements9J 6statements9J
$ or $
else
#
1statements% J
$
!" 8rogram :
=7)! 0rite a program to checG Hhether the giAen number is Iero or
not !
% include &stdio'h(
% include &conio'h(
main))
*
int G+
clrscr)) +
printf),#nter any number ,) +
scanf),Bd/4 JG) +
if)G55>) printf),The number is Iero ,) +
else printf),The number is not Iero ,) +
getch)) +
1
1?% HG 4rite a program to chec; the gi5en number is positi5e or negati5e GH
N include Mstdio.h9
N include Mconio.h9
main;
*
int ; J
clrscr1% J
printf;<!nter any num,er < >
scanf;<BdCD H7 >
- 1A -
if;7FFJ
printf;<The num,er is Kero < >
else if;7LJ
printf;<The num,er is 8ositi*e <>
else
printf;<The num,er is $egati*e < >
getch; >
1
1<% HG 4rite a program to $ind the big number in the gi5en two numbers GH
N include Mstdio.h9
N include Mconio.h9
main;
*
int a& b J
clrscr1% J
printf;<!nter any t.o num,ers AnC >
scanf;<BdBdCD HaD H, >
if;aFF,
printf;<An Gi*en ,oth are eMul < >
else
*
printf;<An The ,ig is < >
i$1a9b% print$1=Id>& a% J
else print$1=Id>& b% J
1
getch; >
1
1A% HG 4rite a program to $ind the biggest number in the gi5en three
num,ers :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int a& b& c J
clrscr1% J
printf;<!nter any three num,ers AnC >
scanf;<BdBdBdCD HaD H,D Hc >
if;aFF, HH aFFc
printf;<Gi*en all are eMual < >
else
*
- 1/ -
printf;<An The ,iggest is < >
if;aL, HH aLc
printf;<BdCD a >
else if;,Lc
printf;<BdCD ,>
else
printf;<BdCD c>
1
getch; >
1
16 9: ?rite a program to find the smallest num,er in the gi*en fi*e num,ers :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int a& b& c& d& e& t J
clrscr1% J
printf;<!nter any fi*e num,ers AnC >
scanf;<BdBdBdBdBdCD HaD H,D HcD HdD He >
if;aFF, HH aFFc HH aFFd HH aFFe
printf;<An Gi*en all are eMual < >
else
*
t F a >
if)t(b) t 5 b+
if)t(c) t 5 c +
if)t(d) t 5 d +
if)t(e) t 5 e +
printf;<An The ,iggest is BdCD t >
1
getch; >
1
1G9: ?rite a program to find the ,iggest and smallest num,ers in the
gi*en fi*e num,ers :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int a& b& c& d& e& 2& y J
clrscr1% J
- 1B -
printf;<!nter any fi*e num,ers AnC >
scanf;<BdBdBdBdBdCD HaD H,D HcD HdD He >
if;aFF, HH aFFc HH aFFd HH aFFe
printf;<An Gi*en all are eMual < >
else
*
K 5 a + y 5 a +
if)K&b) K 5 b+
else y F ,>
if;"Nc " F c >
else if;yLc y F c >
if;"Ne " F e >
else if;yLd y F d >
if;"Ne " F e >
else if;yLe y F e >
print$1=Tn The biggest is Id>& 2% J
print$1=Tn The smallest is Id>& y% J
1
getch; >
1
1O 9: ?rite a program to accept three su,Eects mar7s of a studentD calculate totalD a*erage find the resultD
di*ision and print all details :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int m1& m'& m@& tot J
$loat a5g J
clrscr1% J
printf;<!nter three su,Eects mar7s AnC >
scanf;<BdBdBdCD Hm1D Hm#D Hm/ >
tot F m1 2 m# 2 m/ > a*g F ;float tot 9 / >
printf;<The three su,Eects mar7s BdD BdD BdCD m1D m#D m/ : printf;<An The Total Bd At A*erage
BJ/.#fCD totD a*g >
if;m1N/4 PP m#N/4 PP m/N/4
*
print$1=Tn Cesult is Dail =% J
print$1=Tt di5ision is N"l =% J
1
else
*
- 1. -
printf;<An 'esult is 8ass AtC >
if)aAg(56>) printf),DiAision is I class ,) +
else if)aAg(52>) printf),DiAision is II class/) +
else printf),DiAision is III class/) +
1
getch; >
1
#J 9: ?rite a program to accept an employee)s ,asic salaryD calculate daD hraD pfD net salary using the
follo.ing conditions and print all details
if bas (5 =>>>> 55( da 5 8>B4 hra 5 2>B4 pf 5 22B
=>>>> ( bas (5 2>>> 55( da 5 72B4 hra 5 82B4 pf 5 2>B
2>>> ( bas (5 2>>> 55( da 5 7>B4 hra 5 8>B4 pf 5 =2B
bas & 2>>> 55( da 5 22B4 hra 5 72B4 pf 5 =>B
net 5 bas ? da ? hra @ pf !
Notes 3
# s .i t c h. . . c as e :

(ynta23
switch15ariable%
#
case 6value9 C 6statements9 J
case 6value9 C 6statements9 J
de$ault 3 1statements% J
$
,rea7 :
This ;eyword stops the e2ecution in the gi5en bloc; and come out. 0enerally this is used in switch..case
statements and looping
(tatements.
!" 8rograms :
#1
N include Mstdio.h9
N include Mconio.h9
main;
*
int ; J
clrscr1% J
- 'E -
printf;<!nter any num,er < >
scanf;<BdCD H7 >
s.itch;7
*
case J : printf;<An $um,er is Kero < >
case 1 :
case # :
case / :
case 1 : printf;<An $um,er is less than fi*e < >
,rea7 >
case 4 : printf;<An $um,er is fi*e < >
,rea7 >
default : printf;<An $um,er is greater than fi*e < >
1
getch; >
1
##
N include Mstdio.h9
N include Mconio.h9
main;
*
char ;J
clrscr1% J
printf;<!nter any one of the alpha,ets < >
7 F getche; >
s.itch;7
*
case (a) :
case (A) : printf;<An A for Acti*e < >
,rea7 >
case (,) :
case (=) : printf;<An = for =ra*e < >
,rea7 >
case (c) :
case (C) : printf;<An C for Courage <>
- '1 -
,rea7 >
case (d) :
case (&) : printf;<An & for &are < >
,rea7 >
default : printf;<An Iou are timid < >
1
getch; >
1
#/
N include Mstdio.h9
N include Mconio.h9
main;
*
int a& b& ; J
clrscr1% J
printf;<!nter t.o num,ers AnC >
scanf;<BdBdCD HaD H, >
printf;<AnAn 1. Addition < >
printf;<An #. Su,traction < >
printf;<An /. 0ultiplication < >
printf;<An 1. &i*ision < >
printf;<AnAn Select your choice < >
scanf;<BdCD H7>
printf;<AnC >
s.itch;7
*
case 1 : printf;< The addition BdCD a2, > ,rea7 >
case # : printf;< The su,traction BdCD a3, > ,rea7 >
case / : printf;< The multiplication BdCD a:,> ,rea7 >
case 1 : printf;< The di*ision BdCD a9,> ,rea7 >
default : printf;< In*alid choice <>
1
getch; >
1
Notes 3
/ Conditional !"pressions : ; Q : >
(ynta2 3
- '' -
1condition% Z 1statement1% 3 1statement'% J
!" 8rograms :
#19: ?rite a program to chec7 .hether the gi*en num,er is Kero or not :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int ;J
clrscr1% J
pritnf;<!nter any num,er < >
scanf;<BdCD H7>
;7FFJ Q printf;<$um,er is Kero < : pritnf;<$um,er is not Kero < >
getch; >
1
- '@ -
#49: ?rite a program to find the ,iggest num,er in the gi*en three num,ers :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int a& b& c& t J
clrscr1% J
printf;<!nter any three num,ers AnC >
scanf;<BdBdBdCD HaD H,D Hc>
t F ;aL, Q a : , >
printf;<The ,iggest is BdCD ;tLcQt:c >
getch; >
1
Notes 3
goto"y; :
This $unction locates the cursor position to the gi5en place on the screen. This $unctions prototype has de$ined in the
header $ile #!N"!.S
(ynta23
goto2y1column& row% J
0enerally in M(-)!( mode the screen contains BE columns and '< rows.
!" 8rograms :
#5
N include Mstdio.h9
N include Mconio.h9
main;
*
clrscr1% J
goto2y1'E& @% J
print$1=Sello =%J
goto2y1/E& <%J
print$1=Bhanodaya =% J
goto2y1@<&1'%J
print$1=4elcome =%J
goto2y1<E&'E%J
print$1=To smile =%J
getch1% J
1
- '? -
Notes 3
goto 3
This command changes the e2ecution control to the gi5en statement.
(ynta23
goto 1label% J
1label% 3
1statements% J
!" 8rograms :
#6
N include Mstdio.h9
N include Mconio.h9
main;
*
clrscr1% J
print$1=Sello =% J
print$1=4orld =% J
goto a,c >
printf;<Go out < >
"yK :
print$1=To smile =% J
goto end J
abc 3
print$1=4elcome =% J
goto "yK >
end :
getch; >
1
HG !utput 3
Sello 4orld 4elcome To smile GH
Note 3
Looping Statements :
Cepeating a bloc; o$ statements number o$ times is called Looping.
There are three types o$ looping statements de$ined in # language.
1% do..while& '% while& @% $or.
Note 3
The ;eyword ,goto cn be also used to repeat a bloc; o$ statements number o$ times.
!" 8rograms :
#G
R include Nstdio.hL
- '< -
main;
*
a,c :
printf;<?elcome < >
goto a,c >
1
#O 9: 8rogram to display the first 1J natural num,ers :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int ; J
clrscr1% J
; 8 1 J
abc 3
printf;<Bd <D 7 >
722 >
if;7NF1J goto a,c >
getch; >
1
Notes :
1% do ... while1% 3

(ynta2 3
do
#
1statements%J
R while1condition >
- 'A -
!" 8rograms :
@E% HG 4rite a program to display the $irst 1E natural numbers GH
N include Mstdio.h9
N include Mconio.h9
main;
*
int ; J
clrscr1% J
7 F 1 >
do
*
printf;<Bd <D 7 >
;** J
Rwhile1;M81E% J
getch; >
1
/1 9: ?rite a program to display the e*en num,ers upto the gi*en num,er and find the sum of them
:9
N include Mstdio.h9
N include Mconio.h9
main;
*
int ;& n& s J
clrscr1% J
printf;<!nter any num,er < >
scanf;<BdCD Hn >
; 8 ' J s 8 EJ
do
*
printf;<Bd <D 7 >
s *8 ; J
; *8 ' J
Rwhile 1;M81E% J
printf;<An The sum is BdCD s >
getch; >
1
Notes 3
- '/ -
There is a draw-bac; in do.. while1% staement. "t e2ecutes the conditional statement a$ter e2ecuting the statement.
'% while1% 3

(ynta23
while1condition%
#
1statements%J
$
!" 8rograms :
/# 9: ?rite a program to display the first 1J natural num,ers :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int ; J
clrscr1% J
7 F 1 >
.hile;7NF1J
*
printf;<Bd <D 7 >
722 >
1
getch; >
1
// 9: ?rite a program to display the e*en num,ers upto the gi*en num,er and find the sum of them
:9
N include Mstdio.h9
N include Mconio.h9
main;
*
int ;& n& s J
clrscr1% J
printf;<!nter any num,er < >
scanf;<BdCD Hn >
; 8 ' J s 8 EJ
while 1;M81E%
*
printf;<Bd <D 7 >
s *8 ; J
; *8 ' J
1
- 'B -
print$1=Tn The sum is Id>& s% J
getch1% J
1
@?% HG 4rite a program to chec; whether the gi5en number is :rime or not
8rime $um,er :
; number Hhich is diAisible by = and itselft' !
! I method !
N include Mstdio.h9
N include Mconio.h9
main;
*
int n& ;& sJ
clrscr1% J
print$1=nter any number =% J
scan$1=Id>& -n% J
; 8 1J s 8 EJ
while1;M8n%
*
i$1nI;88E% s**J
;** J
1
if;sFF# printf;<An $um,er is 8rime < >
else printf;<An $um,er is not a 8rime <
getch; >
1
9: II method :9
R include Nstdio.hL
R include Nconio.hL
main;
*
int n& ;& sJ
clrscr1% J
print$1=nter any number =% J
scan$1=Id>& -n% J
; 8 'J s 8 EJ
while1;M8nH'%
*
i$1nI;88E% O s**J brea; J R
;** J
1
if;sFFJ printf;<An $um,er is 8rime < >
- '. -
else printf;<An $um,er is not a 8rime <
getch; >
1
/4 9: ?rite a program to find the num,er of digitsD sum of digitsD and re*erse order of the gi*en num,er :9
N include Mstdio.h9
N include Mconio.h9
main;
*
long int aD , >
int nD sD r >
clrscr; >
printf;<!nter any ,ig num,er < > scanf;<BldCD Ha >
n F J> s F J> , F J>
.hile;aLJ
*
n ** J
r 8 a I 1E J
s *8 r J
b 8 1bG1E% * r J
a H8 1E J
1
printf;<An The num,er of digits BdCD n >
printf;<An The sum of digits BdCD s >
printf;<An The 'e*erse num,er BluCD , >
getch; >
1
@A% HG 4rite a program to chec; whether the gi5en number is Armstrong or not
Armstrong $um,er :
A num,er .hich is eMual to the sum of the cu,es of the digits
is called Armstrong $um,er.
!": 1D 14/D /6JD /61D 1J6 :9
N include Mstdio.h9
N include Mconio.h9
N include Mmath.h9
main;
*
int a& b& r& s J
clrscr1% J
- @E -
print$1=nter any number =% J
scan$1=Id>& -a% J
b 8 a J s 8 EJ
while1a9E%
*
r F a B 1J >
s F po.;rD /> 9: s 2F r : r : r > :9
a 9F 1J>
1
if;,FFs printf;<An The num,er is an Armstrong < >
else printf;<An The num,er is not an Armstrong < >
getch; >
1
Notes 3
@% for; 3

(ynta23
$or 1 initialisation J condition J iteration %
#
1statements% J
$
!" 8rograms :
/6
! 0rite a program to display the odd numbers upto the giAen number !
% include &stdio'h(
% include &conio'h(
main))
*
int n4 a +
clrscr)) +
printf),#nter any number , )+
scanf),Bd/4 Ja )+
! n 5 = +
for ) + a(5n + )
*
printf),Bd ,4 n)+
n 2F # >
- @1 -
1
!
$or1n81J nM8a J n*8'%
print$1=Tn Id = & n% J
getch; >
1
/G
9: ?rite a program to display the e*en num,ers upto the gi*en num,er
and find the sum of them:9
N include Mstdio.h9
N include Mconio.h9
main;
*
int a& n& s J
clrscr1% J
printf;<!nter any num,er < >
scanf;<BdCD Ha >
9: n F # > s F J >
for; > nNFa >
*
printf;<Bd <D n >
s 2F n >
n 2F # >
1
!
!
s 8 E J
$or1n8'J nM8aJ n*8'%
*
printf;<Bd < D n >
s 2F n>
1
!
for;nF#D sFJ > nNFa > s2FnD n2F#
printf;<Bd <D n >
print$1=Tn The sum is Id>& s% J
getch1% J
1
- @' -
/O 9: ?rite a program to find the sum of natural num,ersD e*en num,ersD odd num,ers upto the gi*en
num,er :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int a& n& s& odd& e5en J
clrscr1% J
printf;<!nter any num,er < >
scanf;<BdCD Ha >
$or1n81& s8E& odd8E& e5en8E J nM8a J s*8n& n**%
i$1nI'88E% e5en *8 nJ
else odd *8 nJ
printf;<An The sum of natural num,ers BdCD s >
printf;<An The sum of e*en num,ers BdCD e*en >
printf;<An The sum of odd num,ers BdC D odd >
getch; >
1
?E% HG 4rite a program to $ind the $actorial 5alue o$ the gi5en number
nS F n : ;n31 S
!
N include Mstdio.h9
N include Mconio.h9
main;
*
long int a& $ J
clrscr1% J
print$1=nter any number =% J
scan$1=Ild>& -a% J
! f 5 = +
for) + a(= +)
*
f !5 a +
a @@ +
1
!
for;fF1> aL1> f:FaD a33 >
- @@ -
printf;<An The factorial is BldC D f > getch; >
1
11
9: ?rite a program to display the multiplication ta,le of the gi*en num,er
using all types of loopings. :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int n& ;J
clrscr1% J
printf;<!nter any num,er < >
scanf;<BdCD Hn >
! G 5 = +
do
*
printf),.n Bd K B2d 5 B7d/4 n4 G4 n!G )+
G ?? +
1 Hhile )G&5=>) +
!
!
7 F 1 >
.hile; 7NF 1J
*
printf;<An Bd " B#d F B/d <D nD 7D n:7 >
7 22 >
1
!
for;7F1> 7NF1J> 722
printf;<An Bd " B#d F B/dCD nD 7D n:7>
getch; >
1
?'% HG 4rite a program to display the A(#"" chart
ASCII FFL American Standard Code for Information Interchange :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int ; J
clrscr1% J
9: 7 F J >
- @? -
do
*
print$1=Tt Id Ic>& ;& ;% J
; ** J
if;7B4JFFJ getch; >
T .hile;7NF#44 >
!
! G 5 > +
Hhile)G&5222)
*
printf),.t Bd Bc/4 G4 G) +
G ?? +
if)GB2>55>) getch)) +
1
!
for;7FJ> 7NF#44> 722
*
printf;<At Bd BcCD 7D 7 >
if;7B4JFFJ getch; >
1
getch; >
1
1/ 9: ?rite a program to display the multiplication ta,le of the gi*en num,er using all types of Loopings. :9
$otes :
$ested Loops :
Looping in a loop is called Nesting o$ Loops.
!" 8rograms :
11
N include Mstdio.h9
N include Mconio.h9
main;
*
int n& ;& + J
clrscr1% J
printf;<!nter any num,er < >
scanf;<BdCD Hn >
for;7F1> 7NFn> 722
*
print$1=Tn =% J
$or1+81J +M8;J +**%
printf;<Bd <D E >
- @< -
1
getch; >
1
:; output C
Knter any number +
%
% &
% & ,
% & , 0
% & , 0 +
;:
14
N include Mstdio.h9
N include Mconio.h9
main;
*
int n& ;& + J
clrscr1% J
printf;<!nter any num,er < >
scanf;<BdCD Hn >
for;7F1> 7NFn> 722
*
print$1=Tn =% J
$or1+81J +M8;J +**%
printf;<Bd <D 7 >
1
getch; >
1
:; output C
Knter any number +
%
& &
, , ,
0 0 0 0
+ + + + + ;:
15
N include Mstdio.h9
N include Mconio.h9
main;
*
- @A -
int n& ;& + J
clrscr1% J
printf;<!nter any num,er < >
scanf;<BdCD Hn >
for;7Fn> 7LF1> 733
*
print$1=Tn =% J
$or1+81J +Mn-;J +**%
printf;< < >
for;EF1> ENF7> E22
printf;<Bd <D E >
1
getch; >
1
:; output C
Knter any number +
% & , 0 +
% & , 0
% & ,
% &
1 GH
16
N include Mstdio.h9
N include Mconio.h9
main;
*
int n&+&;&aJ
clrscr1%J
printf;<!nter the any num,erC>
scanf;<BdCDHa>
for;nFa>nLJ>n33
*
print$1=Tn>%J
$or1;81J;M8nJ;**%
printf;<BcCD5127>
for;7F1>7NF#:;a3n31>722
- @/ -
printf;< <>
;81a88n%Zn-13nJ
$or 1J;981J;--%
printf;<BcCD5127>
1
getch;>
1
HG !utput 3
nter any number <
AB#))#BA
AB#) )#BA
@F= =F@
@F F@
@ @ ;:
1G
9: ?rite a program to display the multiplication ta,les upto
the gi*en num,er :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int a& n& ; J
clrscr1% J
printf;<!nter any num,er < >
scanf;<BdCD Ha >
for;nF1> nNFa> n22
*
for;7F1> 7NF1J> 722
print$1=Tn Id 2 I'd 8 I@d =& n& ;& nG;%J
getch1% J
clrscr1% J
1
1
1O
9: ?rite a program to display the list of 8rime num,ers upto
the gi*en num,er :9
N include Mconio.h9
N include Mstdio.h9
main;
*
int a& n& ;& s J
clrscr1% J
- @B -
printf;<!nter any num,er < >
scanf;<BdCD Ha >
for;nF#> nNFa> n22
*
for;7F#D sFJ> 7NFn9#> 722
if;nB7FFJ U s22> ,rea7 > T
if;sFFJ printf;<Bd <D n >
1
getch; >
1
4J 9: ?rite a program to display the list of Armstrong $um,ers upto the gi*en num,er :9
<1% HG 4rite a program to display the Dibonacci (eries upto the gi5en number
3ibonacci Series : >4 =4 =4 24 74 24 :4 =74 2=4 784 224 ''''
In this series eAery element is the sum of its preAious tHo numbers !
4#9: ?rite a program to display a ,o" .ith the gi*en characterD
length and .idth using arrays :9
9: Output :
!nter ,o" length 1J
!nter ,o" .idth 4
!nter any character :
! ! ! ! ! ! ! ! ! !
! !
! !
! !
! ! ! ! ! ! ! ! ! ! !
Notes 3
Arrays 3
An array is a collection o$ similar data type elements. "t stores the elements in contiguous locations. To use any array it
must be declared with its siYe and they may be initialiYed. The siYe must be a constant.
The inde2ing is start $rom E. The arrays are two types.
1% (ingle )imensional arrays& '% Multi )imensional Arrays.
1% (ingle )imensional Arrays 3
(ynta2 3
1type% 15ariable% PsiYeQ J
23
int enoP<Q 8 O <A& A/& ?<& B.& ?<RJ
char enaPQ 8 O ,a& ,b& ,c& ,d R J
- @. -
$loat basPQ 8 O <A.A/& .EE.?<& <A/ R J
!" 8rograms :
4/ 9: ?rite a program to create a 4 cells single dimensional arrayD store 6 in cells and print all :9
N include Mconio.h9
N include Mstdio.h9
main;
*
int ;& aP<Q J
clrscr1% J
printf;<!nter any fi*e num,ers AnC >
$or1;8EJ ;M8?J ;**%
aP;Q 8 / J
printf;<An The array elements are AnC >
for;7FJ> 7N4> 722
printf;<Bd <D aV7W >
getch; >
1
:; 5utputC ( ( ( ( ( ;:
28) ! 0rite a program to accept 2 numbers and print all in reAerse order !
N include Mconio.h9
N include Mstdio.h9
main;
*
int ;& aP<Q J
clrscr1% J
printf;<!nter any fi*e num,ers AnC >
for;7FJ> 7NF1> 722
scanf;<BdCD HaV7W >
printf;<An The array elements in re*erse order AnC > for;7F1> 7LFJ> 733
printf;<Bd <D aV7W >
getch; >
1
44
9: ?rite a program to accept 4 num,ers print allD and find the sum of them :9
N include Mconio.h9
N include Mstdio.h9
- ?E -
main;
*
int ;& s& aP<Q J
clrscr1% J
printf;<!nter any fi*e num,ers AnC >
for;7FJD sFJ> 7NF1>s2FaV7WD 722
scanf;<BdCD HaV7W >
printf;<An The array elements are AnC > for;7FJ> 7N4> 722
printf;<Bd <D aV7W >
printf;<An The sum of elements is BdCD s > getch; >
1
45 9: ?rite a program to create 1J cells single dimensional arrayD
accept O cells *aluesD assign the sum of them to the
last cell and print all :9
N include Mconio.h9
N include Mstdio.h9
main;
*
int ;& aP1EQ J
clrscr1% J
printf;<!nter any nine num,ers AnC >
for;7FJDaVOWFJ> 7NFG>aVOW2FaV7WD 722
scanf;<BdCD HaV7W >
printf;<An The array elements are AnC > for;7FJ> 7N1J> 722
printf;<Bd <D aV7W >
getch; >
1
Notes 3
'% Multi )imensional Arrays 3
23
int aP<QP@Q& bP?QP<QPAQP/Q& .....
char naP@QP'EQ 8 O =abcde$gh>& =rama;rishna>& =Bhanodaya> RJ
A multi dimensional array is a collection o$ another arrays. That means a double dimensional array is a collection o$
single dimensional arrays.
23
The array aP<QP@Q is a collection o$ < single dimensional arrays with siYe @.
!" 8rograms :
- ?1 -
46
9: ?rite a program to create a 4"4 dou,le dimensional arrayD
store 6 in all cells and print them as a matri" :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int 7D ED aV4WV4W >
clrscr)) + output:
for)G5>+ G&2+ G??) ( ( ( ( (
for)L5>+ L&2+ L??) ( ( ( ( (
aMGNMLN 5 9+ ( ( ( ( (
( ( ( ( (
for)G5>+ G&58+ G??) ( ( ( ( (
*
print$1=Tn>%J
$or1+8EJ +M8?J +**%
printf;<Bd <D aV7WVEW >
1
getch; >
1
4G
main;
*
;same as a,o*e
for;7FJ> 7N4> 722
for;EFJ> EN4> E22
aV7WVEW F ;7FFE PP 72EFF1 Q 6 : J>
;same as a,o*e
1
HG !utput 3
/ E E E /
E / E / E
E E / E E
E / E / E
/ E E E / GH
4O
main;
*
;same as a,o*e
- ?' -
for;7FJ> 7N4> 722
for;EFJ> EN4> E22
aV7WVEW F ;7FFJ PP 7FF1 PP EFFJ PP EFF1 Q 6 : J>
;same as a,o*e
1
HG !utput 3
/ / / / /
/ E E E /
/ E E E /
/ E E E /
/ / / / / GH
5J 9: ?rite a program to display a ,o" .ith the gi*en characterD
length and .idth using arrays :9
N include Mstdio.h9
N include Mconio.h9
main;
*
char ch& aP'<QPBEQ J
int ;& +& len& w J
clrscr1% J
printf;<!nter the ,o" length <>
scanf;<BdCD Hlen >
printf;<!nter the ,o" .idth < >
scanf;<BdCD H. >
printf;<!nter a character <>
ch F getche; >
printf;<AnAnC >
for;7FJ> 7N.> 722
for;EFJ> ENlen> E22
aV7WVEW F ;7FFJ PP EFFJ PP 7FF.31 PP EFFlen31 Q ch : /# >
for;7FJ> 7N.> 722
*
print$1=Tn>%J
$or1+8EJ +MlenJ +**%
printf;<Bc <D aV7WVEW >
1
getch; >
- ?@ -
1
HG !utput 3
nter bo2 length 1E
nter bo2 width <
nter any character G
; ; ; ; ; ; ; ; ; ;
; ;
; ;
; ;
; ; ; ; ; ; ; ; ; ; ;:
519: ?rite a program to find the addition matri" of
t.o /"/ matrices :9
N include Mstdio.h9
N include Mconio.h9
main;
*
int aV/WV/WD ,V/WV/WD cV/WV/WD 7D E >
clrscr;>
printf;<!nter O num,ers for firs array AnC >
for;7FJ> 7N/> 722
$or1+8EJ +M@J +**%
scan$1=Id>& -aP;QP+Q %J
printf;<An !nter O num,ers for second array AnC >
for;7FJ> 7N/> 722
$or1+8EJ +M@J +**%
scan$1=Id>& -bP;QP+Q %J
$or1;8EJ ;M@J ;**%
$or1+8EJ +M@J +**%
cP;QP+Q 8 aP;QP+Q * bP;QP+Q J
printf;<An The Addition matri" is AnC>
for;7FJ> 7N/> 722
*
print$1=Tn [ =%J
$or1+8EJ +M@J +**%
printf;<B/d <D cV7WVEW >
printf;<XC>
1
getch;>
1
- ?? -
5# 9: ?rite a program to find the multiplication matri" of
t.o /"/ matrices :9
R include Nstdio.hL
R include Nconio.hL
main;
*
int aV/WV/WD ,V/WV/WD cV/WV/WD 7D ED t >
clrscr;>
printf;<!nter O num,ers for firs array AnC >
for;7FJ> 7N/> 722
$or1+8EJ +M@J +**%
scan$1=Id>& -aP;QP+Q %J
printf;<An !nter O num,ers for second array AnC >
for;7FJ> 7N/> 722
$or1+8EJ +M@J +**%
scan$1=Id>& -bP;QP+Q %J
$or1;8EJ ;M@J ;**%
$or1+8EJ +M@J +**%
$or1t8E& cP;QP+Q8E J tM@J t**%
cP;QP+Q *8 aP;QPtQ G bPtQP+Q J
printf;<An The multiplication matri" is AnC>
for;7FJ> 7N/> 722
*
print$1=Tn [ =%J
$or1+8EJ +M@J +**%
printf;<B/d <D cV7WVEW >
printf;<XC>
1
getch;>
1
- ?< -
Notes3
ST'I$GS :
A string is an array o$ characters. "t ends with a null character. 1 ,TE 889 Null character %
2 3
char na1PAQ 8 O ,a& ,b&c& ,d& ,e& ,TE R J
char na'PAQ 8 =abcde> J
char namesPQPQ 8 O =rama>& =;rishna>& =abcd> R J
char str1P'EQ& str'P?EQ J
Note 3
The $ormat string $or a string 5ariable is Is .
!" programs :
5/
N include Mstdio.h9
N include Mconio.h9
main;
*
char strPBEQJ
clrscr1%J
printf;<!nter any string <>
scanf;<BsCD str >
printf;<An Iou entered the string BsCD str > getch; >
1
HG !utput 3
nter any string udaya bhanu
Xou entered the string udaya GH
Notes 3
scan$1% $unction can accept the string 5alues. But it does not allow spaces in the string. To a5oid this problem gets1%
can be used.
gets; :
This $unction is used to accept the 5alue $or a string 5ariable. This $unctions prototype has de$ined in the header $ile
(T)"!.S.
(ynta2 3
gets15araible% J
2 3
gets1str% J
puts; :
- ?A -
This $unction is used to display the string 5alue o$ the 5ariable. This $unctions prototype has de$ined in the header $ile
(T)"!.S
(ynta2 3
puts1string% J
2 3
puts1=The string is =%J
puts1str% J
!" 8rograms :
51
N include Mstdio.h9
N include Mconio.h9
main;
*
char strVGJW >
clrscr; >
printf;<!nter any string < >
gets;str >
print$1= Xou entered =%J
puts1str%J
getch1% J
1
HG !utput 3
nter any string udaya bhanu
Xou entered the string udaya bhanu GH
54 9: ?rite a program to find the length of a string :9
N include Mstdio.h9
N include Mconio.h9
main;
*
char strPBEQJ int ;J
clrscr1% J
printf;<!nter any string <>
gets;str >
9: 7 F J>
.hile;strV7WSF)AJ)
722 >
!
for;7FJ> strV7W SF)AJ)> 722 >
printf;<An The length is BdCD 7>
getch; >
- ?/ -
1
559: ?rite a program to change the gi*en string into upper case :9
N include Mstdio.h9
N include Mconio.h9
main;
*
char strPBEQ J int ; J
clrscr1% J
printf;<!nter any string AnC >
gets;str >
for;7FJ> strV7WSF)AJ)> 722
if;strV7WLFO6 HH strV7WNF1##
strV7W 3F /# >
!
if; strV7W LF)a) HH strV7W NF)K)
strV7W 3F (a) 3 (A)>
!
printf;<An In upper case BsCD str >
getch; >
1
HG !utput 3
nter any string 6daya Bhanu
In upper case D4@L@ FH@ND ;:
69)! 0rite a program to change the giAen string into loHer case !
5G9: ?rite a program to change the gi*en string into Sentence case
that means the first character into upper case and the remaining
into lo.er case :9
N include Mstdio.h9
N include Mconio.h9
main;
*
char strPBEQ J int ; J
clrscr1% J
printf;<!nter any string < >
gets;str >
if;strVJWLF)a) HH strVJWNF)K) strVJW 3F (a) 3 (A) >
for;7F1> strV7WSF)AJ)> 722
i$1strP;Q98A< -- strP;QM8.E%
strP;Q *8 @' J
- ?B -
printf;<An In sentence case BsCD str >
getch; >
1
HG !utput 3
nter any string 6)AXA BSAN6
In upper case Ddaya bhanu ;:
6O) ! 0rite a program to change the giAen string into Title Case !
:; 5utput C
nter any string 6)AXA BSAN6
In upper case Ddaya Fhanu ;:
9>) ! 0rite a program to copy a string to another !
N include Mstdio.h9
N include Mconio.h9
main;
*
char sVGJWD tVGJW >
int 7>
clrscr; >
printf;<!nter the source string to copy < >
gets;s >
;8EJ
while1sP;QL8TE%
*
tV7W F sV7W >
722 >
1
tV7W F (AJ) >
printf;<An The ne. string is BsCD t >
getch; >
1
619: ?rite a program to concatenate t.o strings :9
N include Mstdio.h9
N include Mconio.h9
main;
*
char aPBEQ& bPBEQ J
int ;& + J
clrscr1% J
printf;<!nter t.o strings AnC >
gets;a > gets;,>
- ?. -
$or1;8EJaP;QL8TEJ ;**% J
$or1+8EJ bP+QL8TEJ ;**& +**%
aV7W F ,VEW >
aV7W F (AJ) > printf;<An The concatenated string is BsCD a > getch; >
1
6#9: ?rite a program to re*erse the gi*en string :9
N include Mstdio.h9
N include Mconio.h9
main;
*
char aVGJWD ,VGJW >
int 7D E >
clrscr; >
print$1=nter any string =% J
gets1a% J
for;7FJ> aV7WSF)AJ)> 722 >
$or1;--& +8EJ ;98EJ ;--& +**%
bP+Q 8 aP;QJ
,VEW F (AJ) >
printf;<An In re*erse order BsCD , >
getch;>
1
HG !utput 3
nter any string bhanodaya
In upper case ayadonahb ;:
97)! Erogram to moAe the giAen name around the screen !
% include &stdio'h(
% include &conio'h(
% include &string'h(
main))
*
int G4 r4 c4 DL+
char strM:>N+
clrscr))+
puts),#nter your name ,)+ gets)str)+
G 5 strlen)str)+
DL 5 =>>>>+
Hhile)PGbhit)))
*
for;rF1> rNF#/> r22
- <E -
*
goto"y;1Dr> printf;<BsCD str>
delay;&L> clrscr;>
1
for;cF1> cNFGJ37> c2F/
*
goto"y;cD#/> printf;<BsCD str>
delay;&L> clrscr;>
1
for;rF#/>rLJ> r33
*
goto"y;GJ37Dr> printf;<BsCD str>
delay;&L> clrscr;>
1
for;cFGJ37>cLJ> c3F/
*
goto"y;cD1> printf;<BsCD str>
delay;&L> clrscr;>
1
1
1
619: 8rogram to fall and replace the gi*en name character ,y character :9
N include Mstdio.h9
N include Mconio.h9
N include Mstring.h9
N include Mdos.h9
main;
*
char naPBEQJ
int r& c& ;& n& )LJ
clrscr1%J
printf;<!nter your name <> gets;na>
7 F strlen;na>
&L F #JJJ>
clrscr;>
for;nF1> nN4> n22
*
for;cFJ> cN7> c22
*
for;rF1> rNF14> r22
*
goto"y;c2#JDr>printf;< <>
goto"y;c2#JDr21>printf;<BcCD naVcW>
- <1 -
delay;&L>
1
1
for;cFJ> cN7> c22
*
for;rF15> rL1> r33
*
goto"y;c2#JD r> printf;< <>
goto"y;c2#JD r31> printf;<BcCD naVcW>
delay;&L>
1
1
1
1
649: 8rogram to display the gi*en name as a ,o" :9
N include Mstdio.h9
N include Mconio.h9
main;
*
char strP'EQ& aP'<QP'EQJ
int ;& +& n J
clrscr1 %J
printf;<!nter Iour name < >
gets;str >
$or1n8EJ strPnQL8TEJ n**% J
$or1;8EJ ;MnJ ;**%
for;EFJ> ENn> E22
if;7FFJ aV7WVEW F strVEW >
else if;EFFJ aV7WVEW F strV7W>
else if;EFFn31 aV7WVEW F strVn3731W >
else if;7FFn31 aV7WVEW F strVn3E31W >
else aV7WVEW F /# >
for;7FJ> 7Nn> 722
*
print$1=Tn>%J
$or1+8EJ +MnJ +**%
printf;<Bc <D aV7WVEW >
1
getch; >
- <' -
1
HG !utput 3
nter Xour name Bhanodaya
B h a n o d a y a
h y
a a
n d
o
d n
a a
y h
a y a d o n a h B
;:
- <@ -
Notes 3
ST'I$G.@ functions :
To manipulate the strings the # authors designed some $unctions in the header $ile (TC"N0.S
1% strlen1%3
This $unction returns an integer 5alue that is the length o$ the string. length means the number o$ characters.
(ynta23
int strlen1string% J
'% strupr1% 3
This $unction changes the gi5en string into uppercase characters.
(ynta2 3
strupr1string% J
@% strlwr1% 3
This $unction changes the gi5en string into lowercase characters.
(ynta2 3
strlwr1string% J
?% strcpy1% 3
This $unction copies the string to another string.
(ynta2 3
strcpy1target& source% J
<% strcat1% 3
This $unction adds two strings.
(ynta2 3
strcat1destination& second% J
A% strre51% 3
This $unction change the gi5en string into re5erse order.
(ynta2 3
strre51string% J
/% strcmp1% 3
This $unction compares two strings and returns Yero when both are same.
(ynta2 3
int strcmp1$irst& second% J
!" 8rograms :
66 9: 8rogram to demonstrate the li,rary functions of ST'I$G.@ :9
N include Mstdio.h9
N include Mconio.h9
N include Mstring.h9
main;
*
- <? -
char aPBEQ& bPBEQ J
clrscr1% J
print$1=nter a string =% J
gets1a% J
printf;<An The gi*en string is BsCD a>
printf;<An The length of string is BdCD strlen;a >
printf;<An In %pper case BsCD strupr;a >
printf;<An In Lo.er case BsCD strl.r;a >
strcpy;,D a >
printf;<An The ne. string is BsCD , >
strre*;,>
printf;<An In re*erse order BsCD , >
printf;<An The difference is BdCD strcmp;aD, >
getch;>
1
HG !utput 3
nter a string Bhanodaya
The gi5en string is Bhanodaya
The length o$ string is .
"n 6pper case BSAN!)AXA
"n Lower case bhanodaya
The new string is bhanodaya
"n re5erse order ayadonahb
The di$$erence is 1
;:
- << -
F%$CTIO$S :
The $unction is a piece o$ code. These $unctions are used to reduce the repetition o$ coding.
The $unctions are two types.
1% )eri5ed $unctions&
'% 6ser-de$ined $unctions.
The deri5ed $unctions are pro5ided by the # writers and they de$ined them in header $iles. To use these $unctions the
header $ile must be included at the top o$ the program.
4e can create our own $unctions. To write any $unction there are three steps.
1% Dunctions declarations& '% Dunctions calling& @% Dunction de$inition.
or
1% Dunction de$inition& '% Dunction calling.
"n the $unction declaration andHor in the de$inition the name must be $ollow the return data type& and it should be
$ollowed by parenthesis. "n the parenthesis there may be arguments with their data types. "$ the $unction does not
return any 5alue it must be declared as 5oid. The de$ault return type is int.
(ynta23
1datatype% 1$unctionname% 1argumentstype% J HG Dunction declaration GH
functionname6arguments9 J :; "unction
calling ;:
6datatype9 6functionname9 6arguments9 :; "unction
definition ;:
#
1statements% J
$
These $unctions are three types.
1% No arguments with no return 5alue $unctions&
'% Arguments with no return 5alue $unctions&
@% Arguments with return 5alue $unctions.
1% No arguments with no return 5alue $unctions 3

6G
N include Mstdio.h9
N include Mconio.h9
5oid $irst15oid% J
5oid second15oid% J
5oid third15oid%
*
printf;<An This is in third function < >
1
*oid fourth;*oid
*
- <A -
printf;<An This is in fourth function < >
1
*oid main;
*
clrscr1% J
print$1=This is in Main =% J
$irst1% J
second1% J
third1% J
$ourth1% J
printf;<An This is in main again < >
getch; >
1
*oid first;*oid
*
printf;<An This is in first function < >
1
*oid second;*oid
*
printf;<An This is in second function < >
1
HG !utput 3
This is in Main
This is in $irst $unction
This is in second $unction
This is in third $unction
This is in $ourth $unction
This is in mainagain GH
6O
N include Mstdio.h9
N include Mconio.h9
*oid replicate;*oid
*
int ;J
$or1;81J ;M8<EJ ;**%
printf;<:C >
1
*oid main;
*
clrscr1% J
replicate1% J
print$1=Tn Sello Tn>% J
replicate1% J
- </ -
print$1=Tn 4orld Tn>% J
replicate1% J
print$1=Tn 4elcome Tn>% J
replicate1% J
getch1%J
1
HG !utput 3
Sello
4orld
4elcome
;:
/* 2) Arguments with No Return value functions */
GJ
N include Mstdio.h9
N include Mconio.h9
*oid replicate;int nD int ch
*
int ;J
$or1;81J ;M8nJ ;**%
printf;<BcCD ch >
1
*oid main;
*
clrscr1% J
replicate1@E&G% J
print$1=Tn Sello Tn>% J
replicate1AE&N% J
print$1=Tn Bhanodaya Tn>% J
replicate1<E&I% J
print$1=Tn 4elcome Tn>% J
replicate1?E&\% J
getch1%J
1
HG !utput 3
Sello
Bhanodaya
))))))))))))))))))))))))))))))))))))))))))))))))))
4elcome
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
- <B -
!
G1
N include Mstdio.h9
N include Mconio.h9
5oid add1int& int% J
5oid subtr1int& int% J
5oid mult1int a& int b%
*
printf;<An The multiplication BdCD a:, >
1
*oid di*;int 7D int E
*
printf;<An The di*ision BfCD ;float7 9 E >
1
*oid main;
*
int a& b J
clrscr1% J
printf;<!nter any t.o num,ers AnC >
scanf;<BdBdCD HaD H, >
add1a& b% J subtr1a& b% J
mult1a& b% J di51a& b% J
getch; >
1
*oid add;int mD int n
*
int ;J
; 8 m - n J
printf;<An The addition is BdCD 7 >
1
5oid subtr1p& q%
int p& q J
*
int r J
r 8 p - q J
printf;<An The su,traction BdC D r >
1
- <. -
/* 3. Arguments with Return value functions */
G#
N include Mstdio.h9
N include Mconio.h9
int add;int "D int y
*
int Y J
Y 8 2 * yJ
return Y J
1
int su,tr;int pD int M
*
return p3M >
1
int mult1int& int % J
int di51int& int% J
int main;
*
int aD ,D c >
clrscr; >
printf;<!nter any t.o num,ers AnC >
scanf;<BdBdCD HaD H, >
c F add;aD , > printf;<An The addition is BdCD c > printf;<An The su,traction BdCD su,tr;aD, >
c F mult;aD, > printf;<An The multiplication BdCD mult;aD, > printf;<An The di*ision BdCD di*;aD, >
getch1% J
return EJ
1
int mult;int aD int ,
*
return a:,>
1
int di*;int mD int n
*
int p 8 m H nJ
return pJ
1
- AE -
G/ Important :
9: 8rogram to demonstrate all types of functions :9
N include Mstdio.h9
N include Mconio.h9
9: $o arguments .ith $o return *alue functions :9
5oid looping15oid% J
5oid condition15oid% J
9: Arguments .ith $o return *alue functions :9
5oid add1int& int% J
5oid mult1int& int% J
9: Arguments .ith 'eturn *alue functions :9
int subtr1int& int% J
int di51int& int% J
int main;
*
looping1% J
return EJ
1
*oid looping;
*
char ch 8 ,y J
while1ch88y KK ch88X%
*
clrscr1% J
condition1% J
goto2y1?<& ''% J
print$1= )o you want to cotinue 1yHn% =% J
ch F getche ;>
1
1
*oid condition;
*
int aD ,D 7>
printf;<An !nter any t.o num,ers AnC >
scanf;<BdBdCD HaD H, >
gotoKy)7>4 2) + printf),=' ;ddition , )+
gotoKy)7>4 6) + printf),2' Subtraction ,) +
gotoKy)7>4 9) + printf),7' Qultiplication ,) +
gotoKy)7>4 :) + printf),8' DiAision ,) +
goto2y1@E& 1E %J
print$1=nter Xour choice =% J
scanf;<BdCD H7 >
goto2y11E& 1<%J
switch1;%
*
case 1 : add;aD , > ,rea7 >
- A1 -
case # : printf;< The su,traction BdCD su,tr;aD, >
,rea7 >
case / : mult;aD, > ,rea7 >
case 1 : printf;< The di*ision BdCD di*;aD, >
,rea7>
default : printf;< In*alid choice < >
1
1
*oid add;int aD int ,
*
printf;<An The addition BdCD a2, >
1
int su,tr;int "D int y
*
int Y 8 2 - yJ
return Y J
1
*oid mult;int pD int M
*
int r J
r 8 p G q J
print$1=The multiplication Id>& r% J
1
int di*;int aD int ,
*
int c J
c 8 a H b J
return cJ
1
Notes 3
8'!8'OC!SSO' CO00A$&S :
The commands which start with hash 1N% are called :reprocessor
#ommands.
2 3
N de$ine :" @.1?1<.
N include Mstdio.h9
N include =conio.h>
N de$ine A 1./
- A' -
de$ine 3
This command is used to de$ine our own constants and macros.
!" 8rograms :
G1
N include Mstdio.h9
N include Mconio.h9
N de$ine MN main1%
N de$ine p$ print$
N de$ine cls clrscr1%
N de$ine wait getch1%
N de$ine s$ scan$
N de$ine :" @.1?1<.
N de$ine msg =nter the radius o$ circle =
N de$ine area1g% :"GgGg
N de$ine per1g% 'G:"Gg
0$
*
float r >
cls J
p$1msg% J
sf;<BfCD Hr >
pf;<An The area of circle is BfCD areaY > pf;<An The perameter of circle BfCD perY > .ait >
1
Notes 3
include :
This command is used to include the $iles which contains the de$inition
o$ $unctions.
There are two types to include the $iles.
1% N include M name 9
This type o$ command includes the $ile which is located in the
speci$ied directory. These speci$ications are set by selecting
the )irectories command $rom !ptions menu.
'% N include = name =
This type o$ command includes the $ile which is located in the
current directory andHor in the speci$ied directory.
- A@ -
!" 8rograms :
G4
9: Sa*e this progam as S%=.C :9
N include Mstdio.h9
N include Mconio.h9
int add;int "D int y
*
int Y J
Y 8 2 * yJ
return Y J
1
int su,tr;int pD int M
*
return p3M >
1
9: Sa*e and e"ecute this program as 0AI$.C :9
R include <su,.cC
int mult1int& int % J
int di51int& int% J
int main;
*
int aD ,D c >
clrscr; >
printf;<!nter any t.o num,ers AnC >
scanf;<BdBdCD HaD H, >
c F add;aD , > printf;<An The addition is BdCD c > printf;<An The su,traction BdCD su,tr;aD, >
c F mult;aD, > printf;<An The multiplication BdCD mult;aD, > printf;<An The di*ision BdCD di*;aD, >
getch1% J
return EJ
1
int mult;int aD int ,
*
return a:,>
1
int di*;int mD int n
*
int p 8 m H nJ
return pJ
1
- A? -
Notes 3
STO'AG! CLA%S!S :
The declared 5ariables are generally stored in memory de5ices. But by
using the storage clauses they can be stored either in memory de5ices or
in #:6 registers.
These storage clauses are ? types. The 5ariables initialisation
depends on this type.
1% auto& '% register& @% static& ?% e2tern
1% auto 3
This ;eyword is an option. "t stores the 5ariable in memory de5ice.
"t assigns a +un;1garbage% 5alue to the 5ariable. The 5ariable which
declared in a bloc; that is a5ailable in that bloc; only. The de$ault
type is auto.
!" 8rograms :
G5
N include Mstdio.h9
N include Mconio.h9
main;
*
auto int 7>
*
int 7 F 4 > output :
*
auto int 7 F #J >
clrscr; >
printf),.n Bd/4 G )+ &*
1 +
1
printf;<An BdCD 7 > 145
getch; >
1
G6
N include Mstdio.h9
N include Mconio.h9
main;
*
int ; J
- A< -
clrscr1% J
printf;<Bd AnCD 7 >
for;7F1> 7NF4> 722
display; >
getch; >
1
display;
*
auto int ; 8 'E J
print$1= Id = & ;%J
7 2F / >
1
HG !utput 3
?<A/
'E 'E 'E 'E 'E GH
Notes 3
'% register 3
This ;eyword stores the 5ariable in #:6 registers. "t assigns a +un;1garbage% 5alue to the 5ariable. "n #:6 registers it
cant store more and big 5alues li;e $loats& doubles&..etc. "t can store !nly chars and integers. These 5ariables are also
local that means the 5ariables which declared in a bloc; are a5ailable in that bloc; only.
0enerally these 5ariables are used to generate the looping statements.
!" 8rograms
GG
N include Mstdio.h9
N include Mconio.h9
main;
*
register int ; J
clrscr1% J
printf;<Bd AnCD 7 >
for;7F1> 7NF1JJ> 722
printf;<Bd <D 7 >
getch; >
1
Notes 3
- AA -
@% static 3
This ;eyword stores the 5ariable in memory de5ice. "t initialises the
5ariable as E. The scope o$ 5ariable is local that means
the 5ariables which declared in a bloc; are a5ailable in that bloc;
only. But it does not destroy the 5ariables 5alue when end that bloc;.
"t ta;es the pre5ious 5alue when the controller entered into that
bloc; again.
!" 8rograms :
GO
N include Mstdio.h9
N include Mconio.h9
main;
*
static int 7 >
clrscr; >
printf;<Bd AnCD 7 >
for;7F1> 7NF4> 722
display; >
getch; >
1
display;
*
static int ; 8 'E J
print$1= Id = & ;%J
7 2F / >
1
HG !utput 3
E
'E '@ 'A '. @' GH
Notes 3
?% e2tern 3
This ;eyword stores the 5ariable in memory de5ice. "t initialises the
5ariable as E. The scope o$ 5ariable is global. This 5ariable is
declared be$ore the main1% . The 5ariables 5alue can be changed
in the $unctions.
- A/ -
!" 8rograms :
OJ
N include Mstdio.h9
N include Mconio.h9
int 7 >
main;
*
clrscr1% J
print$1=Tn Id>& ;% J
7 F 4 >
disp11% J
disp'1% J
print$1=Tn Id>& ;% J
getch1% J
1
disp1;
*
printf;<An BdCD 7 >
7 2F / >
1
disp#;
*
int ; 8 'E J
print$1=Tn Id>& ; %J
disp@1% J
1
disp/;
*
printf;<An BdCD 7 >
1
HG !utput
E < 'E B B GH
- AB -
Notes 3
(TC6#T6C( 3
A structure is a collection o$ 5ariety o$ data type elements. This is created with the ;eyword struct.
struct 1name%
#
1elements declaration%J
$ J
struct 1name% 15ariable% J
15ariable%.1element%
2 3
1% struct employee
#
int enoJ
char enamePBEQJ
$loat basJ
$J
struct employee emp 8 O <& =rama>& <AEE R J
'% struct employee
#
int enoJ
char enamePBEQJ
$loat basJ
R emp 8 O <& =rama>& <AEE R J
@% struct
#
int enoJ
char enamePBEQJ
$loat basJ
R emp 8 O <& =rama>& <AEE R J
- A. -
!" 8rograms :
O1
N include Mstdio.h9
N include Mconio.h9
main;
*
struct ,oo7
*
int pagesJ
char titleP?EQ J
$loat price J
1 +
struct ,oo7 ,7 F U 4JJD <Let us CCD 164 T >
clrscr; >
printf;<An The title of ,oo7 BsC D ,7.title > printf;<An The num,er of pages BdC D ,7.pages > printf;<An The
price of ,oo7 B.#fC D ,7.price > getch; >
1
O#
N include Mstdio.h9
N include Mconio.h9
main;
*
struct ,oo7
*
int pagesJ
char titleP?EQ J
$loat price J
1 +
struct boo; b; J
clrscr1% J
printf;<!nter the num,er of pages of ,oo7 < >
scanf;<BdC D H,7.pages >
printf;<!nter the ,oo7 title < >
scanf;<BsCD ,7.title >
printf;<!nter the cost of ,oo7 < >
scanf;<BfCD H,7.price>
printf;<An The title of ,oo7 BsC D ,7.title > printf;<An The num,er of pages BdC D ,7.pages > printf;<An The
price of ,oo7 B.#fC D ,7.price > getch; >
1
- /E -
O/
9: Array of Structures :9
N include Mstdio.h9
N include Mconio.h9
main;
*
struct ,oo7
*
int pagesJ
char titleP?EQ J
$loat price J
1 +
int 7 >
struct ,oo7 ,7V/W F U U 4JJD <Let us CCD 164 TD
U /4JD <Graphics under CCD #/4 T D
U GJJD <&atastructures through C and C22 <D /4J T
1 +
clrscr1% J
$or1;8EJ ;M@J ;**%
*
printf;<AnAn The title of ,oo7 BsC D ,7V7W.title >
printf;<An The num,er of pages BdC D ,7V7W.pages >
printf;<An The price of ,oo7 B.#fC D ,7V7W.price >
getch; >
1
1
O8) ! Structures to 3unctions !
% include &stdio'h(
% include &conio'h(
struct booG
*
int pages+
char titleM8>N +
float price +
1 +
main))
*
struct ,oo7 ,7 F U 4JJD <Let us CCD 164 T >
clrscr; >
display1b;.pages& b;.title& b;.price %J
dispstrct1b;% J
getch1 %J
- /1 -
1
display;int pgD char naVWD float pr
*
printf;<An The title of ,oo7 BsCD na>
printf;<An The num,er of pages BdCD pg>
printf;<An The price of ,oo7 BfCD pr >
1
dispstrct;struct ,oo7 ,
*
printf;<An The title of ,oo7 BsCD ,.title>
printf;<An The num,er of pages BdCD ,.pages>
printf;<An The price of ,oo7 BfCD ,.price >
1
O4 9: Structures in structure :9
N include Mstdio.h9
N include Mconio.h9
struct ,oo7
U int pages> char nameV1JW> float price > T >
struct pens
U int Mty> char nameV1JW> float price > T >
struct shop
*
char nameP?EQ& streetP?EQ J
struct boo; b; J
struct pens pn J
1 +
main;
*
struct shop sh F U <%daya =oo7 .orld <D <Chintal <D
U 1#JJD <Test your s7ills in CCD 164 T D
U 4JD <'eynoldsCD 1# T
1 +
clrscr; >
printf;<An The shop name BsC D sh.name > printf;<An The shop address Bs <D sh.street>
printf;<AnAn The ,oo7 title BsC D sh.,7.name > printf;<An The num,er of pages in the ,oo7
BdCDsh.,7.pages > printf;<An The cost of each ,oo7 B.#fC D sh.,7.price >
printf;<AnAn The name of pen BsC D sh.pn.name > printf;<An The Muantity of pens BdC D sh.pn.Mty >
printf;<An The cost of each pen B.#fC D sh.pn.price >
getch; >
1
- /' -
O5 9: ?rite a program to interchange the *alues of t.o *aria,les :9
- /@ -
Notes 3
8OI$T!'S
This topic is the most important in #.
To use any 5ariable it must be declared with its data type be$ore the $irst e2ecutable statement. By declaring a 5ariable
the compiler reser5es the required space in memory between A? ;b and 1'B ;b. 5ery cell has a unique address in
memory. This address is a number&that is an integer.
The 5ariables stored in the memory can be accessed with their addresses using pointers.To access with pointers we ha5e
to use two new operators.
J 778 @ddress of
! 778 !alue at address of
2 3
int a 8 <J
a 889 <
-a 889 A<<EE
G1-a% 889 <
These address 5alue can be stored in another 5ariable. But that must be a pointer 5ariable o$ the same type to the
5ariable.
!" 8rograms :
O6
N include Mstdio.h9
N include Mconio.h9
main;
*
int ;& Gp& GGq J
clrscr1% J
7 F 6> p F H7> M F Hp>
printf;<The *alue of 7 is BdCD 7 > printf;<An The address of 7 is BuCD H7> printf;<An The *alue at address
Bu is BdCD H7D :;H7 >
printf;<An The *alue of 8 is BuCD p > printf;<An The *alue at address Bu is BuCD HpD :;Hp >
printf;<An The *alue at address Bu is BdCD pD :p >
printf;<An The *alue of M is BuCD M > printf;<An The *alue at address of Bu is BuCD HMD :;HM >
printf;<An The *alue at address Bu is BuCD MD :M>
printf;<An The integer *alue is BdCD :;:M >
getch; >
1
HG !utput 3
The 5alue o$ ; is /
The address o$ ; is A<<'?
The 5alue at address A<<'? is /
- /? -
The 5alue o$ : is A<<'?
The 5alue at address A<<'' is A<<'?
The 5alue at address A<<'? is /
The 5alue o$ q is A<<''
The 5alue at address o$ A<<'E is A<<''
The 5alue at address A<<'' is A<<'?
The integer 5alue is / GH
OG
N include Mstdio.h9
N include Mconio.h9
main;
*
int a& Gap J
$loat b& Gbp J
char c& Gcp J
clrscr; >
printf;<An The siKe of int is Bd and pointer is BdCD siKeof;aD siKeof;ap > printf;<An The siKe of float is Bd and
8ointer is BdCD siKeof;,DsiKeof;,p > printf;<An The siKe of char is Bd and 8ointer is BdCD siKeofZD siKeof;cp >
getch; >
1
Notes 3
8ointers in Functions :
The $unctions can be send some arguments to the de$inition and may
ta;e a return 5alue. "$ the 5alue o$ these 5ariables changed in the
$unctions that does not e$$ected to the $unction calling.
To change the 5alue a$ter calling the $unction the 5alues can be send by re$erence. That means the address o$ the
5ariable can be send to change the 5alue.
!" 8rograms :
OG 9: ?rite a program to interchange the *alues of t.o *aria,les using
functions
A CALL =I +AL%! : :9
R include Nstdio.hL
R include Nconio.hL
main;
*
int a8'E& b8@E J
clrscr1% J
printf;<The initial *alues are AnC >
- /< -
printf;<a F Bd At , F BdCD aD , >
s.ap;aD, >
print$1=TnTn A$ter swapping in main Tn>% J
print$1= a 8 Id Tt b 8 Id>& a& b% J
getch1% J
1
s.ap;int "D int y
*
int t >
t 8 2J 2 8 y J y 8 t J
print$1=TnTn A$ter swapping Tn>%J
print$1= 2 8 Id& y 8 Id>& 2& y%J
1
HG !utput 3
a 7 &* b 7 ,*
. 7 ,* y 7 &*
a 7 &* b 7 ,* ;:
= CALL =I '!F!'!$C! :
R include Nstdio.hL
R include Nconio.hL
main;
*
int a8'E& b8@E J
clrscr1% J
printf;<The initial *alues are AnC >
printf;<a F Bd At , F BdCD aD , >
s.ap;HaDH, >
print$1=TnTn A$ter swapping in main Tn>% J
print$1= a 8 Id Tt b 8 Id>& a& b% J
getch1% J
1
s.ap;int :"D int :y
*
int t >
t 8 G2J G2 8 Gy J Gy 8 t J
print$1=TnTn A$ter swapping Tn>%J
print$1= 2 8 Id& y 8 Id>& G2& Gy%J
1
HG !utput 3
a 7 &* b 7 ,*
. 7 ,* b 7 ,*
a 7 ,* b 7 &*
;:
- /A -
Notes 3
Arrays .ith 8ointers :
An array is a collection o$ similar data type elements mentioning with a single 5ariable. The address o$ $irst element is
considered the address o$ the array. The array elements can be accessed using the address o$ array and the inde2 5alue.
!" 8rograms :
M
R include Nstdio.hL
R include Nconio.hL
main;
*
int 7D aV4W F U 1JD #JD /JD 1JD 4J T >
clrscr; >
for;7FJ> 7N4> 722
*
printf;<An the addres of Bd element Bu BuCD 7D HaV7WD a27 >
printf;<the *alue is Bd Bd Bd BdCD aV7WD :;a27D :;72aD 7VaW >
1
getch ; >
1
M
N include Mstdio.h9
N include Mconio.h9
main;
*
int Ga& n J
clrscr1% J
printf;<!nter the num,er of elements you .ant < >
scanf;<BdCD Hn >
accept1a& n% J
display1a& n% J
getch; >
1
accept;int :pD int n
*
int 7>
- // -
printf;<!nter Bd num,ers An <D n >
for;7FJ> 7Nn> 722
scanf;<BdCD p27 >
1
display;int :pD int n
*
int 7>
printf;<An The elemetns are AnC >
for;7FJ> 7Nn> 722
printf;<Bd <D :;p27 >
1
M
N include Mstdio.h9
N include Mconio.h9
R define 0 4
main;
*
int aPMQ J
clrscr1% J
accept1a& M% J
display1a& M% J
getch1% J
1
accept;int :pD int 7
*
int n >
print$1=nter any Id numbers Tn>& ;% J
$or1n8EJ nM;J n**%
scan$1=Id>& p*n% J
1
display;int dVWD int 7
*
int n >
printf;<An The array elements are AnC >
$or1n8EJ nM;J n**%
print$1=Id =& dPnQ % J
1
Notes 3
malloc; :
- /B -
This $unction is used to allocate the required space in the memory while e2ecuting the program. This $unctions
prototype was de$ined in the header $ile ALL!#.S
There is an another $unction to allocate memory. that is calloc1%.
The malloc1% assigns +un; 5alues the allocated space. But calloc1% assigns E to the allocated space.
(ynta23
1pointer% 8 1pointertype% malloc1 siYe G number% J
1pointer% 8 1pointertype% calloc1 siYe & number % J
Note 3
"$ the compiler $ailed to allocate the required space this $unction returns a N6LL 5alue.
!" 8rograms :
M
N include Mstdio.h9
N include Mconio.h9
N include Malloc.h9
main;
*
int Gp& n& ;& sJ
clrscr1% J
printf;<!nter the num,er of elements < >
scanf;<BdCD Hn >
p F ;int : malloc;siKeof;int : n > if;pFF$%LL
*
printf;<%na,le to allocate the reMuired space < >
e"it;J >
1
printf;<!nter Bd num,ers AnCD n >
for;7FJD sFJ> 7Nn>s2FpV7WD 722
scanf;<BdCD p27 >
print$1=Tn The elements are Tn>% J
$or1;8EJ ;MnJ ;**%
print$1=Id =& pP;Q %J
printf;<An The sum is BdCD s >
getch; >
1
M 9: ?rite a program to sort the gi*en num,ers using Linear Sort techniMue :9
N include Mstdio.h9
N include Mconio.h9
N include Mstdlib.h9
N include Malloc.h9
- /. -
main;
*
int Gp& nJ
clrscr1% J
printf;<!nter the num,er of elements < >
scanf;<BdCD Hn >
p 8 1int G% malloc1'Gn% J
i$1p88N6LL%
*
printf;<An %na,le to allocate the reMuired space < >
e"it;J>
1
accept1p& n% J
linear1p& n% J HG bubble1p& n% J GH
display1p& n% J
getch1% J
1
accept;int :pD int n
*
int ; J
print$1=nter Id numbers Tn>& n% J
for;7FJ> 7Nn> 722
scanf;<BdCD p27 >
1
display;int :pD int n
*
int 7 >
printf;<An The elements are < >
for;7FJ> 7Nn> 722
printf;<Bd <D :;p27 >
1
!
linear;int aVWD int n
*
int 7D ED t >
for;7FJ> 7Nn> 722
$or1+8;J +MnJ +**%
i$1aP;QMaP+Q%
*
t F aV7W > aV7W F aVEW > aVEW F t >
1
1
!
- BE -
linear;int :aD int n
*
int 7D ED t >
for;7FJ> 7Nn> 722
for;EF7> ENn> E22
if;:;a27 N :;a2E
*
t 8 G1a*;% J
G1a*;% 8 G1a*+% J
G1a*+% 8 t J
1
1
,u,,le;int aVWD int n
*
int tD 7D E >
$or1;8EJ ;Mn-1J ;**%
$or1+8EJ +Mn-1J +**%
if;aVEW N aVE21W
*
t 8 aP+Q J
aP+Q 8 aP+*1Q J
aP+*1Q 8 t J
1
1
! bubble)int !a4 int n)
*
int t4 G4 L +
for)G5>+ G&n@=+ G??)
for)L5>+ L&n@=+ L??)
if)!)a?L) & !)a?L?=) )
*
t 8 G1a*+% J
G1a*+% 8 G1a*+*1% J
G1a*+*1% 8 t J
1
1
!
Notes 3
String 8ointers to Functions :
!" 8rograms :
$) ! QoAing the giAen string as a Canner !
- B1 -
% include &stdio'h(
% include &conio'h(
% include &string'h(
% include &dos'h(
Aoid main))
*
char !str 5 , Chanodaya is a super hero ,+
clrscr))+
Hhile)PGbhit)))
*
substr)str)+ delay)=>>)+
goto"y;#JD 1#> printf;<BsCDstr>
1
getch;>
1
!
su,str;char :str
*
char Gdst& cJ int i81& +8EJ
c 8 GstrJ
while1G1str*i%L8TE%
*
:;dst2E F :;str2i>
i22> E22>
1
G1dst*+% 8 cJ
G1dst*+*1% 8 ,TEJ
strcpy1str&dst%J
1
!
su,str;char strVW
*
char dstPBEQ& ch J
int ;& + J
ch 8 strPEQ J
;81J +8EJ
while1strP;QL8TE%
*
dstP+Q 8 strP;Q J
;**J +**J
1
dstP+**Q 8 ch J
dstP+Q 8 ,TE J
strcpy1str& dst% J
- B' -
1
Notes 3
Structures .ith 8ointers :
The elements o$ a structure 5ariable can be accessed using a period operator between the 5ariable and the element. To
access the elements using the address o$ the 5ariable the , -9 , operator must be used.
15ariablepoitner% -9 1element%
!" 8rograms :
M
N include Mconio.h9
N include Mstdio.h9
struct ,oo7
U int pages> char titleV1JW> float price > T >
main;
*
struct ,oo7 ,7 F U 4JJD <8ointers in CCD 164.JJ T >
struct ,oo7 :, >
clrscr; >
, F H,7 >
printf;<An The ,oo7 title BsC D ,7.title > printf;<An The num,er of pages BdC D ,7.pages > printf;<An The
cost of ,oo7 B.#f < D ,7.price >
printf;<AnAn The ,oo7 title BsC D ,3Ltitle > printf;<An The num,er of pages BdCD ,3Lpages > printf;<An The
cost of ,oo7 B.#f <D ,3Lprice >
printf;<AnAn The siKe of structure *aria,le BdCDsiKeof;,7 > printf;<An The siKe of structure pointer BdCD
siKeof;, >
getch; >
1
M 9: Structure 8ointers to Functions :9
N include Mconio.h9
N include Mstdio.h9
struct ,oo7
U int pages> char titleV1JW> float price > T >
main;
*
struct ,oo7 ,7 F U 4JJD <8ointers in CCD 164.JJ T >
clrscr; >
disp5ar1b;% J
disppntr1-b;% J
getch; >
- B@ -
1
disp*ar;struct ,oo7 ,7
*
printf;<An The ,oo7 title BsC D ,7.title >
printf;<An The num,er of pages BdC D ,7.pages >
printf;<An The cost of ,oo7 B.#f < D ,7.price >
printf;<An The siKe of structure *aria,le BdC D siKeof;,7 >
1
disppntr;struct ,oo7 :,
*
printf;<AnAn The ,oo7 title BsC D ,3Ltitle >
printf;<An The num,er of pages BdCD ,3Lpages >
printf;<An The cost of ,oo7 B.#f <D ,3Lprice >
printf;<An The siKe of structure pointer BdCD siKeof;, >
1
Notes 3
FIL! @A$&LI$G I$ C
6sing # programs the data $iles and te2t $iles can be manipulated. To use any $ile it must be loaded into memory.
"n # programs the $ile pointer where the $ile stored can be $ound.
fopen;:
This $unction is used to open the required $ile in the required mode and returns the $ile pointer where the $ile stored. "$
it is unable to open in the gi5en mode it returns a constant 5alue N6LL.
(ynta2 3
D"L G 1$ilepointer% J
1$ilepointer% 8 $open1=$ilename>& =mode> %J
modes 3
- - - -
=w> 889 To create the $ile and store the data
=a> 889 To add the data to the $ile
=r> 889 To read the data $rom the $ile
2 3
D"L G$pJ
$p 8 $open1=data.t2t>& =w>%J
fclose; :
The fileH which opened in memory must be closed to avoid the
data corruption. To close the file the function fclose69 must be
used.
3ynta. C
$close1$ilepointer%J
- B? -
2 3
$close1$p% J
fputc;:
This $unction is used to store the characters in the data $ile opened in the $ilepointer.
(ynta2 3
$putc1char& $ilepointer% J
2 3
$putc1ch& $p% J
fgetc; :
This $unction is used to read a character to the 5ariable $rom the $ile pointer.
(ynta2 3
char 5ariable 8 $getc1$ilepointer% J
2 3
ch 8 $getc1$p% J
!" 8rograms :
M 9: ?rite a program to create a te"t file &ATA and store some data. :9
N include Mstdio.h9
N include Mconio.h9
N include Mstdlib.h9
main;
*
FIL! :fp >
char ch >
$p 8 $open1=)ATA>& =w>% J
i$1$p88N6LL%
*
printf;<An %na,le to open the gi*en file < >
e"it;J >
1
.hile;1
*
ch 8 getchar1%J
i$1ch88!D% brea; J
$putc1ch& $p% J
1
fclose;fp >
1
- B< -
M 9: ?rite a program to read the te"t from the file &ATA:9
N include Mstdio.h9
N include Mconio.h9
N include Mstdlib.h9
main;
*
FIL! :fp >
char ch >
clrscr1% J
$p 8 $open1=)ATA>& =r>% J
i$1$p88N6LL%
*
printf;<An File not found < >
e"it;J >
1
.hile;1
*
ch 8 $getc1$p%J
i$1ch88!D% brea; J
putchar1ch% J
1
$close1$p% J
getch1% J
1
M9: ?rite a program to read the te"t from the file &ATA display in
%pper case characters :9
N include Mstdio.h9
N include Mconio.h9
N include Mstdlib.h9
main;
*
FIL! :fp >
char ch >
clrscr1% J
$p 8 $open1=data>& =r>% J
i$1$p88N6LL%
*
printf;<An File not found < >
e"it;J >
1
.hile;1
- BA -
*
ch 8 $getc1$p%J
i$1ch88!D% brea; J
i$1ch98./ -- chM81''% ch -8 @' J
putchar1ch% J
1
$close1$p% J
getch1% J
1
M9: ?rite a program to read the te"t from the file &ATA copy to another
in file in upper case characters :9
N include Mstdio.h9
N include Mconio.h9
N include Mstdlib.h9
main;
*
FIL! :fsD :ft >
char chD :srcD :trg >
clrscr; >
printf;<!nter the source file to copy < >
scanf;<BsCD src >
$s 8 $open1src& =r>% J
i$1$s88N6LL%
*
printf;<An Source File not found < >
e"it;J >
1
printf;<An !nter the target file to copy < >
scan$1=Is>& trg% J
$t 8 $open1trg& =w>% J
i$1$t88N6LL%
*
printf;<An %na,le to open the target file < >
e"it;1 >
1
.hile;1
*
ch 8 $getc1$s%J
i$1ch88!D% brea; J
i$1ch98./ -- chM81''% ch -8 @' J
putchar1ch% J
$putc1ch& $t% J
1
- B/ -
fclose;fs > fclose;ft >
getch; >
1
Notes 3
fprintf; :
This $unction stores the data in the $ile.
(ynta2 3
$print$1$ilepointer& =$ormat string>& 5ariables%J
2 3
$print$1$p& =Id Is I$>& eno& ena& bas%J
fscanf; :
This $unction reads the data $rom the $ile.
(ynta2 3
$scan$1$ilepointer& =$ormat string>& 5ariables%J
2 3
$scan$1$p& =IdIsI$>& -eno& ena& -bas%J
!" 8rograms :
M9: ?rite a program to create a data file !08.&ATD accept employee num,erD
nameD ,asic salary and store all in the data file:9
N include Mconio.h9
N include Mstdio.h9
N include Mstdlib.h9
main;
*
D"L G$p J
int enoJ char enaP?EQJ $loat bas J
char ans8y J
clrscr1% J
$p 8 $open1=M:.)AT>& =w>% J
i$1$p88N6LL%
*
printf;<An %na,le to open in the reMuired mode < >
e"it;J >
1
.hile;ansFF)y) PP ansFF)I)
*
printf;<An !nter !mployee $um,er < >
scanf;<BdCD Heno >
- BB -
printf;< !nter !mployee $ame < >
scanf;<BsCD ena >
printf;< !nter =asic Salary < >
scanf;<BfCD H,as >
fprintf;fpD <An Bd Bs BfCD enoD enaD ,as >
printf;<&o you .ant to continue < >
ans F getche; >
1
getch;>
1
M9: ?rite a program to read the records from the data file !08.&ATD
calculate daD hraD pfD net salary and print all :9
N include Mconio.h9
N include Mstdio.h9
N include Mstdlib.h9
main;
*
D"L G$p J
int enoJ char enaP?EQJ
$loat bas& da& hra& p$& net J
clrscr1% J
$p 8 $open1=M:.)AT>& =r>% J
i$1$p88N6LL%
*
printf;<An File not found < >
e"it;J >
1
.hile; fscanf;fpD <BdBsBfCD HenoD enaD H,as L J
*
da 8 bas G 'E H 1EE J
hra 8 bas G @E H 1EE J
p$ 8 bas G 1E H 1EE J
net 8 bas * da * hra - p$ J
printf;<AnAn !mployee $um,er BdCD eno >
printf;<An !mployee $ame BsCD ena >
printf;<An =asic Salary B.#fCD ,as >
printf;<An &a B.#f At @ra B.#f At 8f B.#fCD daD hraD pf >
printf;<An $et Salary B.#fCD net >
getch; >
1
1
- B. -
Notes 3
f.rite; :
This $unction is used to store the structures in the $ile in binary
mode.
(ynta23
$write 1 1pointer to 5ariable%& 1siYe o$ 5ariable%&
1numbero$5ariables%&1$ilepointer% %J
23
$write1 -emp& siYeo$1emp%& 1& $p%J
fread; :
This $unction is used to read the structures $rom the $ile in binary le5el.
3ynta.C fread 6 6pointer to variable9H 6siNe of variable9H
6numberofvariables9H6filepointer9 9J

K.C fread6&empH siNeof6emp9H %H fp9J
!" 8rograms :
M
N include Mstdio.h9
N include Mconio.h9
struct employee
U int eno> char enaV#JW> float ,as > T >
main;
*
struct employee emp J
D"L G$p J
char ans J
clrscr1% J
$p 8 $open1=empbn.dat>& =wb>% J
i$1$p88N6LL%
*
printf;<%na,le to open the data file < >
e"it;J >
1
do
*
printf;<AnAn !nter employee $um,er < >
scanf;<BdCD Hemp.eno >
- .E -
printf;<!nter !mployee $ame < >
scanf;<BsCD emp.ena >
printf;<!nter =asic Salary < >
scanf;<BfCD Hemp.,as >
f.rite;HempD 1D siKeof;empD fp > printf;<&o you .ant to add more < >
ans F getche; >
T .hile;ansFF)y) PP ansFF)I) >
1
M
N include Mstdio.h9
N include Mconio.h9
struct employee
U int eno> char enaV#JW> float ,as > T >
main;
*
struct employee emp >
FIL! :fp >
clrscr; >
$p 8 $open1=empbn.dat>& =rb>% J
i$1$p88N6LL%
*
printf;<%na,le to open the data file < >
e"it;J >
1
.hile; fread;HempD 1D siKeof;empD fp L J
*
printf;<AnAn !mployee $um,er BdCD emp.eno >
printf;<An !mployee $ame BsCD emp.ena >
printf;<An =asic Salary B.#fCD emp.,as >
getch; >
1
1
M
N include Mstdio.h9
N include Mconio.h9
struct employee
- .1 -
U int eno> char enaV#JW> float ,as > T >
main;
*
struct employee emp >
FIL! :fsD :ft >
clrscr; >
$s 8 $open1=empbn.dat>& =rb>% J
i$1$s88N6LL%
*
printf;<%na,le to open the data file < >
e"it;J >
1
$t 8 $open1=emp.dat>& =w>% J
i$1$t88N6LL%
*
printf;<An %na,le to open the target file < >
e"it;1>
1
.hile; fread;HempD 1D siKeof;empD fs L J
*
printf;<AnAn !mployee $um,er BdCD emp.eno >
printf;<An !mployee $ame BsCD emp.ena >
printf;<An =asic Salary B.#fCD emp.,as >
fprintf;ftD <An Bd Bs BfCD emp.enoD emp.enaD emp.,as>
getch; >
1
1
Notes 3
CO00A$& LI$! A'G%0!$TS :
The arguments can be passed to any $unction when they are calling.The main1% is also a $unction and some arguments
can be passed to it $rom the M(-)!( prompt.
Sere we ha5e to use the words arg5& argsPQ .
Sere arg5 is the an integer 5alue and it is the number o$ arguments passed and GargsPQ is an array o$ strings contain
the arguments
(ynta23
main1int arg5& char GargsPQ%
!" 8rograms :
M 9: This program demonstrates a,out the arguments passed to
the function main; :9
- .' -
R include Nstdio.hL
*oid main;int arg*D char :argsVW
*
int 7 >
printf;<An The num,er of arguments gi*en BdCD arg* >
print$1=Tn The arguments are Tn>% J
$or1;8EJ ;Marg5J ;**%
printf;<An BsCD argsV7W >
1
HG (a5e this program as AC0.#
A$ter compilation it creates an ob+ect $ile AC0.!BV and
an e2ecutable $ile AC0.7& which can be e2ecuted at M(-)!(
prompt
OpromptP @>G abc lkG .yN mnb ;:
$)! Erogram to create a file Hhich can create teKt file !
N include Mstdio.h9
N include Mstdlib.h9
*oid main;int arg*D char :argsVW
*
char ch>
FIL! :fp >
if;arg*SF#
*
printf;<An In*alid num,er of arguments < >
e"it;J >
1
$p 8 $open1argsP1Q& =w>% J
i$1$p88N6LL%
*
printf;<An %na,le to create the gi*en file < >
e"it;1 >
1
.hile;1
*
ch 8 getchar1% J
i$1ch88!D% brea; J
$putc1ch& $p% J
1
- .@ -
printf;<An 1. file created AnC >
1
:;
(a5e this program as #CAT.#
A$ter compilation it creates an e2ecutable $ile #CAT.7& which
can be e2ecuted at M(-)!( prompt.
OpromptP =>K@TK 6filename9 ;:
$) ! Erogram to create a file Hhich can read a teKt file !
N include Mstdio.h9
N include Mstdlib.h9
*oid main;int arg*D char :argsVW
*
char ch>
FIL! :fp >
if;arg*SF#
*
printf;<An In*alid num,er of arguments < >
e"it;J >
1
$p 8 $open1argsP1Q& =r>% J
i$1$p88N6LL%
*
printf;<An File not found 3 BsCD argsV1W >
e"it;1 >
1
.hile;1
*
ch 8 $getc1$p% J
i$1ch88!D% brea; J
putchar1ch% J
1
1
HG (a5e this program as (S!4.#
- .? -
A$ter compilation it creates an e2ecutable (S!4.7
OpromptP 3H5E 6filename9 ;:
$)! Erogram to create a file Hhich can copy the teKt from a file to another !
R include Nstdio.hL
R include Nstdli,.hL
*oid main;int arg*D char :argsVW
*
FIL! :fsD :ft >
char ch >
if;arg*SF/
*
printf;<In*alid num,er of arguments <>
e"it;J >
1
$s 8 $open1argsP1Q& =r>% J
i$1$s88N6LL%
*
printf;<An %na,le to open the source file < >
e"it;1 >
1
$t 8 $open1argsP'Q&>w>% J
i$1$t88N6LL%
*
printf;<An This target file Bs not found <D argsV#W >
e"it;# >
1
.hile; ;chFfgetc;fs SF !OF
fputc;chD ft >
$close1$s% J $close1$t% J
print$1=Tn 1. Dile copied =% J
1
:; 3ave this file as "=I.=
OpromptP "=I 6source9 6target9 ;:
Notes 3
random; :
- .< -
This $unction returns the 5alue which is between E and 1 less than the gi5en number. This $unctions prototype has
de$ined in the header $ile (T)L"B.S
(ynta2 3
random1n%J
This $unction returns any number $rom E to n-1 .
te"tattr; H te"t,ac7ground; :
This $unction changes the te2t color to the gi5en color.
- .A -
G'A8@ICS
0enerally the screen is in te2tmode. "t can be changed by
the display adopters. There are a number o$ adopters li;e F0A& #0A&0A& ...
The normal te2t mode has '< rows and BE columns. "t can be changed using the M!) command in M(-)!(.6sing
# programs we can design some graphics by changing the screen $rom te2t mode to graphics mode.
initgraph; :
This $unction changes the screen $rom te2t mode to graphics mode. But here we ha5e to mention the display dri5er and
mode. To use this command the $ile 0AF0A.B0" must be in the current directory. This $unctions prototype has
de$ined in the header $ile 0CA:S"#(.S
(ynta23
initgraph1 1address o$ dri5er%& 1address o$ mode%& 1path to $ile% %J
2 3
int gdr 8 )T#T& gmdJ
initgraph1-gdr& -gmd& =#3TT#> %J
detectgraph; :
This $unction detects the using graphic dri5er and modes. "t assign the 5alues to the 5ariables.
(ynta2 3
detectgraph1 1address o$ graphic dri5er%& 1address o$ graphic mode% %J
2 3
int gdr& gmdJ
detectgraph1-gdr& -gmd%J
closegraph; :
This $unction closes the graphics mode and changes to te2t mode.
(ynta23
closegraph1%J
setcolor; :
This $unction changes the displaying color o$ screen. "n F0AS" we can use 1A colors. The color can be mentioned as
integer.
(ynta23
setcolor1integer% J
2 3
setcolor1C)% J
setcolor1?% J
set,7color; :
This $unction changes the bac;ground color o$ screen .
- ./ -
(ynta2 3
setb;color1integer% J
23
setb;color1XLL!4% J
setb;color11<%J
putpi"el; :
This $unction highlights the pi2el1picture element% at the gi5en co-ordinates to the gi5en color .
(ynta2 3
putpi2el12-coordinate& y-coordinate& color% J
2 3
putpi2el1@'E& '?E& <% J
line; :
This $unction displays a line between the gi5en coordinates.
(ynta2 3
line121& y1& 2'& y' %J
2 3
line1'EE&@EE& '?E& @/E %J
lineto; :
This $unction displays a line to the gi5en coordinates $rom the current coordinates.
(ynta2 3
lineto12'& y'% J
2 3
lineto1?EE& AEE% J
circle; :
This $unction displays a circle with the gi5en center coordinates and the radius.
(ynta2 3
circle12& y& radius% J
2 3
circle1@'E& '?E& 1EE% J
ellipse; :
(ynta2 3
ellipse12& y& st-angle& end-angle&2-radius& y-radius %J
2 3
ellipse1 @'E& '?E& E& @AE& 'EE& 1EE %J
arc; :
- .B -
(ynta2 3
arc12& y& st-angle& end-angle& radius %J
2 3
arc1@'E& '?E& ?<& 1@<& 'EE % J
rectangle; :
(ynta2 3
rectangle1 21& y1& 2'& y' %J
2 3
rectangle1 'EE& 1<E& ??E& @'E %J
sette"tstyle; :
This $unction sets the displaying te2t style .
(ynta2 3
sette2tstyle1 $ont& direction& siYe %J
$onts 3 direction 3 S!C"]^)"C& FCT^)"C siYe 3
2 3 sette2tstyle1 @& E& < %J
outte"t"y; :
This $unctions displays the gi5en te2t at the gi5en coordinates with the setted style.
(ynta2 3
outte2t2y12& y& te2t% J
underlined 8 re$er again

Das könnte Ihnen auch gefallen