Sunteți pe pagina 1din 40

Software: -

Software is a program or collection of programs.


This software divided into 2 parts
1)packages
2)languages
1)Packages:-
A package is set of predefined program or commands
e.g.:-
ms-office
2)languages:-
A language is a set of haracters arranged in a
meaningful format or in s!stematic order.
This language further classified into 2 t!pes.
1) "ow level language: -
A language whose instructional format is near to the
machine understanda#le language is called low level
language.
$.g.: -
Ada.
%igh level language: -
A language whose instructional format is near to the
user understanda#le language is known as high level
language.
$.g.: -
&'&" (PASA" ()&*T*A+ (,ava
-iddle level language:-
A language( which supports #oth low level and high
level languages( is known as -iddle level language.
e.g.:-
(..
$valuation of c:-
/n earlier da!s there was 2 languages &'&" was
the language used for commercial applications and
)&*T*A+ was the language used for scientific
calculations .Then omputer Scientists thought for a
language which is the complete replacement of
)&*T*A+ 0 &'&" ./n this procedure A"1&" was
the first step ./t was not up to the mark of user
re2uirements .
/n +e3t 'P"4'asic om#ined Programming
"anguage) was the language( 'ut it was failed to replace
the previous languages.
5en Thompson introduced a language which is the
complete replacement of )&*T*A+ 0 &'&" .%e
named his language with )irst alpha#et of 'P" as '-
language( 'ut it is /nterpreter #ased language.
/n 1672 8ennis *ich working at AT 0 T 'ell
la#oratories in 9.S.A introduced a language which is
the complete replacement of )&*T*A+ 0 &'&"
and it is purel! compiler #ased language( he named his
language with second alpha#et of 'P" as -language.
Translators: -
Translators are the mediators #etween user and s!stem
that can used to translate the information from one
form to another form.
)ollowing are the translators: -
1) /nterpreter: -ompile the program line #! line.
2) ompiler: -ompile the total program at a time and
displa!s a message #o3 with errors and warnings.
)eatures of -language: -
1) /t is ompiler #ased language.
2) /t is a -iddle level language.
:) is a Structure oriented language.
;) allows programming at #it level.
<) is function-oriented language.
=) allows user his own compilers( interpreters(
functions>
7) Programming approach is from top to down.
?) /t is case sensitive language.
haracter set: -
A-@( a-A characters
B-6 num#ers
Special characters like C D(E F(4 )(G(0(..............
Hords: -There are two t!pes of words
1) *eserved words: -A word( which defined #! the
developers for the support of user is known as *eserved
Hords.
e.g.:-
int (float( goto (#reak (void (char (long
(dou#le (.............
2) 9ser defined words:-
A word which defined #! the 9ser according to his
program is known as 9ser defined words.
$.g.: -
rno (name ( course(.........
+ote: -
A *eserved word can not #e considered as a user
defined word.
)unction:-
A function is a su#program with set of statements to do
a specific task.
there are two t!pes of functions in c.
1)"i#rar! functions:-
The functions which are developed #! the developers
for the support of user are known as li#rar! functions.
e.g.:-
SI*T4) (P&H4) (.........
2)9ser defined functions:-
The functions which are developed #! the 9ser
According to his program are known as user defined
functions.
e.g.:-
Add4)(Su#4)(.........
Structure of the -language.
/n $ver! program language has written in a form(
which is followed #! its compiler.
)ollowing is the structure of the .
1)8ocumentation Section.
/n this section we can write following properties
i) Title of the program
ii) 9ser address
iii) /nstructions
iv) "ogic used in the program
v) reated 8ate 0 Time.
The a#ove mentioned information need not to #e
converted into machine language4BJs and 1Js).So that
this will #e given #Kw comments like follows
KL .............. Statements ................................ LK
2) "inkage section.
/n this section we have to link some header files
with our program. A header file is a group of several
li#rar! functions.
$.g.: -
GincludeMstdio.hN
stdio.hstandard input and output header file
GincludeMconio.hN
conio.hconsole input and output header file
GincludeMmath.hN
:) 8eclaration section.
/n this section we have to declare constants( user
defined functions( macros(....
$.g.: -
8eclaring a constant
G define pi :.1;
;) 1lo#al varia#les.
/n this section we can declare the glo#al varia#les.
int i=0;
<) -ain section.
The name itself indicates this is the main section
for ever! program.
-ain includes following 2 parts
1) 8eclaration of varia#les
2) $3ecuta#le statements
Structure:-
main4)
E
8eclaration of varia#lesO
$3ecuta#le statementsO
F
=) Su#program section.
/n this section we can define and design the user defined
functions.
/+P9T and &9T functions
printf4 ):-
This function is used to print an! messages on the
screen
s!n:-
printf4P-essageP)O
Hrite a Program to print the message as Hel -ome to

KLThis is m! )irst programLK


GincludeMstdio.hN
main4)
E
printf4PHelcome to P)O
F
Alt.)6 -----N To compile the program
trl.)6 -----N To *un the Program
Alt.)< -----N To See the *esults of the program.
To open : -
lick &n Start -enu
lick on *un
T!pe as c:QtcQ#inQtc
And click on ok.
L Hrite a program to print the user address.
KL 9ser Address LK
GincludeMstdio.hN
main4)
E
printf4PRara PrasadP)O
printf4PG 1=-1-<:?P)O
printf4P%anamkondaP)O
printf4P%!dera#adP)O
F
$scape se2uence characters:-
Qn --------N to move the cursor to +ew line
Qt --------N To Produce the horiAontal ta#.
Q# --------N )or 'ackspace
Qa --------N )or 'eep sound
QQ --------N )or PQP
QP --------N )or dou#le codes4P)
clrscr4 ):-
This function is used to clear the previous output of
the program. /t is availa#le in a header file called
Pconio.hP
Lwrite a program to implement the $sc in the program.
KL$scape Se2uence characters LK
GincludeMstdio.hN
GincludeMconio.hN
main4)
E
clrscr4)O
printf4PSoftechP)O
printf4PQnQtSoftechP)O
printf4PQnQQsoftechQQP)O
printf4PQnQPSoftechQPP)O
printf4PQnQ#SoftechP)O
printf4PQnsQ#oftechP)O
F
oKp:-
Softech
Softech
QSoftechQ
PSoftechP
Softech
&ftech
Raria#le:-
A varia#le is a memor! location whose value
changes from time to time.
onstant: -
A constant is a memor! location whose value does
not change at an! time.
8ata t!pes: -
A data t!pe is t!pe of the data that is which t!pe of
values we can store in to the respective varia#les
int: -
This data t!pe allows integer values onl! range starts
from -:27=? to :27=7.it occupies 2' of space.
short int: -
This data t!pe allows integer values onl! range is less
than that of PintP. /t occupies 2' of space.
long int :-
This data t!pe allows integer values onl! range is
greater than that of PintP. /t occupies ;' of space.
float: -
This data t!pe allows decimal num#ers. /t occupies ;'
of space.
char:-
This data t!pe allows characters. /t occupies 1' of
space.
S!nta3 for declaring a varia#le:-
8atat!pe var1( var2( var:(.....O
)ormatted iKp and oKp functions:-
printf4):-4oKp function)
This function is used to print an! messages or
values of the varia#les.
s!n:-
printf4P)ormatstringsK-essagesP(varia#les)O
scanf4):-4iKp function)
This function is used to accept the values in to the
respective varia#les at *un Time
s!n:-
scanf4P)ormatstringsP(0var1(0var2(....)O
%ere J0J indicates address of the respective varia#les.
)ormat strings: -
8ata t!pe )ormat strings
/nt Sd
short int Ssd
long int Sld
)loat Sf
har Sc
String4group of chars) SS
? Hrite a program to calculate the addition of the 2
values.
? Hrite a program to calculate the addition of the 2
? values accept the values at run time.
&perators /n :-
1) Arithmetical &perators:-
These operators are used to perform all mathematical
calculations.
&perator 8escription
. Addition
- Su#traction
L -ultiplication
K 8ivision 4Iuotient)
S 8ivision 4*emainder)
2) 9nar!K'inar! &perators:-
9nar!: -
/f an operand or varia#le is given with a single
operator then it is called 9nar! operator.
e.g.:-
a.( a-(.....
'inar!: -
/f a single operator is given with 2 operands or 2
varia#les then it is called as #inar! operator.
e.g.:-
a.#( a-#( aL#( ...........
:) *elational operators4omparison &perators):-
These operators are used to provide the relation
ships or to compare the values of the varia#les.
&perator 8escription

M "ess than
N 1reater than
NT 1reater than or e2ual
MT "ess than or e2ual
T T $2ual to
UT +ot $2ual to
;) Assignment &perator:-4T)
This &perator Assigns or store the value or
e3pression result to the left side varia#le.
eg:-
aT1BO
/t reads as Pa assigns 1BP
<) conditional operator:- 4 V :)
This operator is used to give condition to the values
or e3pression for two or more operands .
S!nta3 :- varia#le1Nvaria#le2 V true statement : false
statement

$3 :-
aN#V printf4WA is #ig W): printf4W # is #igX)O
Hrite a program to calculate area and perimeter of
the circle.

Hrite a program to perform all #inar! operations
Hap to swap the given two values.
Hap to swap the given two values with out using the
third varia#le
siAeof4):-
This function is used to return the siAe of the specified
varia#le Kdata t!pe.
? Hrite a program to print the siAes of the all data
t!pes.
? Hap to calculate the addition of the given 2 digit
num#er.
9nformated iKp and oKp functions:-
This functions are not allow the format strings
iKp functions:-
1)getch4):-
this function is used to accept the character in to the
respective varia#le at run time which is not visi#le.
s!n:-
charYvarTgetch4)O
2)getchar4):-
this function is used to accept the character in to the
respective varia#le at run time which is visi#le.
s!n:-
charYvarTgetchar4)O
oKp functions:-
1)putch4):-
This function is used to print the character of the
respective varia#le on the screen ./t will not allow an!
$scape se2uence character.
s!n:-
putch4charYvar)O
2)putchar4):-
This function is used to print the character of the
respective varia#le on the screen ./t will allow the
$scape se2uence characters.
s!n:-
putchar4charYvar)O
9nformated iKp and oKp string functions:-
1)puts4):-
This function is used to print the string on the screen.
s!n:-
puts4PStringP)O
2)gets4):-This function is used to accept a string in to the
respective varia#le.
s!n:-
gets4StringYvar)O
L write a program to implement 9nformated iKp nad oKp
functions in the program.
getch4):-
This function is used to sgive the pause to 9ser at run
time.
ontrol Structures:-
These Structures are used control the compiler at
run time and e3ecute the statements according to the
given conditions.
These are 2 t!pes
1) onditional Structures
2) /terative Structures 4or loops)
onditional Structures: -
These Structures are e3ecuting the statements
depending up on given condition.
There are following ; t!pes of conditional statements.
simple if
if .. else
+ested if 4/f Hith /n The /f)
else..if 4lader if)
1) Simple if:-
Structure: -
if 4condition)
E
statementsO
F
/n the a#ove structure the statements are
e3ecuted when the specified condition is true otherwise
control avoids the statements from e3ecution.
2) if..else:-
Structure: -
if4condition)
E
statemetns1O
F
else
E
statemetns2O
F
/n the a#ove structure if specified condition is true
then statements1 are e3ecuted other wise statements2
are e3ecuted.
? Hrite a program to print #ig num#er in given 2
num#ers using simple if.
? Hrite a program to find whether the given num#er is
positive or negative.
+ote: -
1) $ver! control statement will not terminated #!
semicolon 4O).
2) 'oundaries4E( F) are compulsor! for multiple
statements( #ut these are optional for single
statement.
? Hrite a Program to find whether the user is eligi#le
for vote or not
+ested if: -
/f a simple if..else statement is given with in
another if then it is called +ested if.
Structure: -
if4con-1)1BBNp
E
if4con-2)<BNp
statemetns1O
else
statemetns2O
F
else
E
if4con-1)
statements:O
else
staments;O
F
/n the a#ove structure if con-1 is true then
control will enter into the if #lock. /f con-2 is
true then statements1 are e3ecuted other wise
it will e3ecute statemetns2( #ut the
statements: 0;are e3ecuted when con-1 is false.
else if ladder: -
/f a simple if ..else statement is given with in the else
#lock then it is called else if ladder.
Structure: -
if4con-1)
statemetns1O
else if4con-2)
statemetns2O
else
statemetns:O
/n the a#ove structure if con-1 is true then control
will e3ecute statemetns1 other wise control will enter
into the else #lock( here if con-2 is true then control will
e3ecute statemnts2 other wise statements:.
? Hrite a program to find the #ig num#er in given :
num#ers.
"ogical operators: -
These operators are used to Zoin the num#er of
conditions and returns result as either true or false
)ollowing are the logical operators:-
1)and400)
2)or 4[[)
:) +ot4U)
1) And400)
This operator Zoins the num#er of conditions and
returns result as True when all the given conditions are
true otherwise it returns false.
Truth ta#le: -
P I P00I
1 B B
B 1 B
B B B
1 1 1
2)&r4[[):-
This operator Zoin the num#er of conditions and
returns result as True when all the given conditions or
an! one of the given conditions is true otherwise it
returns false.
truth ta#le:-
P I p[[2
1 B 1
B 1 1
B B B
1 1 1
:)+ot4U):-
This operator Zoins the num#er of conditions and
returns result as True when all the given conditions are
false otherwise it returns false.
truth ta#le:-
p Up
1 B
B 1
Hrite a program to find the #ig num#er in given
:digit num#er.
Hrite a program to calculate the 'ill amount of the
onsumer according to the following conditions.
Amount 8iscount
M:BBB :S
NT:BBB and M<BBB ;S
NT<BBB and M1BBBB <S
NT1BBBB =S
input values are 2t! and rate.
Hrite a program to find the net salar! of person
According to the following conditions.
'asicsal 'onus
------------------- ---------
9p to <BBB 12.:;<S
A#ove <BBB and 9p to 1BBBB 1;.2:;S
A#ove 1BBBB and 9p to :BBBB 1=.<:;S
A#ove :BBBB 17S
Hap to calculate the #ill of the customer according to
the following ta#le.
T!pe &f the *oom Per 8a! harge
------------------------- ---------------------
&rdinar! 2<B
8elu3e :BB
Ac ;BB
Hrite a program to calculate the student results.
Hap to find whether the given character is vowel or
consonant

Switch-ase
'! using conditional statements we can provide one
condition or group of conditions onl!. This will cause
for comple3it! of the program. To avoid this comple3it!
we have to use Pswitch caseP. A switch case is a control
statement that can provide no.of cases or
omparisons Kconditions to e3ecute the statements in
the program.
Structure:-
switch4varia#le)
E
case 1:statements1O
#reakO
case 2:statements2O
#reakO
...
...
...
case n:statementsn
#reakO
default:
F
/n the a#ove structure the value of the varia#le
matched with an! one of the given cases that respective
statements are e3ecuted( other wise control will e3ecute
the default statements. %ere P#reakP statement is given
#Kw the cases to #reak the continuit! of the switch-case.
Hap to illustrate the switch-case concept.
9nformated iKp and oKp string functions:-
1)puts4):-
This function is used to print the string on the screen in
a new line
s!n:-
puts4PStringP)O
2)gets4):-This function is used to accept a string in to the
respective String varia#le.
s!n:-
gets4StringYvar)O
Hap to perform all arithmetical operations using
switch case.
Hap to perform all arithmetical operations #!
accepting arithmetical operator.
Hap to find whether the given character is vowel or
consonant using switch case.
onditional &perator 4 Ternar! &perator)
This operator works( same like as simple if ..else
statement.
s!n:-
4condition)VtruevarKtruemsg :falsevarKfalsemsgO
e.g.:-
aT2B #T;B
aT4aN#)Va:#O cT4aM#)Va:#O
;B 2B
Hap to find whether the given num#er is odd or
even.
Hap to find the #ig num#er in given 2 num#ers using
conditional operator.
goto:-
/t is iterative statement used to move the cursor
position to the specified la#el name. To avoid the
infinite loops we have to provide proper conditions.
s!n:-
goto la#elnameO
L wap to print n natural num#ers.
/ncrement operators:-4..)
This operator increments the value of the varia#le #!
one.
1) Post increment operator 4a..)
This operator first assigns the value and then increment
the value.
e.g.:-
aT1BO
pTa..O
p a
C1BD C11D
2) Pre /ncrement &perator:-4..a)
This operator first increments the value and after words
assigns the value.
eg:-
aT1BO
pT..aO
p a
C11D C11D
8ecrement operator: -
This operator 8ecrements the value of the varia#le #!
one.
1) Post decrement operator 4a--)
This operator first assigns the value and then
8ecrement the value.
eg:-
aT1BO
pTa--O
p a
C1BDC6D
2) Pre 8ecrement &perator:-4--a)
This operator first decrements the value and after
words assigns the value.
eg:-
aT1BO
pT--aO
p a
C6D C6D
ompound Assignment 4Assignment) &perator:-
aTa.# ------N a.T#O
aTa-# ------N a-T#O
aTaL# ------N aLT#O
aTaK# ------N aKT#O
aTaS# ------N aST#O
Hap to implement /ncrement and 8ecrement
&perators.
/terative statements4loops):-
this statements are controll statements used to
repeat the set of statements for n num#er of times.
there are following : t!pes of loops
1)for
2)while
:)do..while
)or:-
sturcture:-
for4initialiAatonOconditionO/ncrK8ecr)
E
statementsO
F
/n the a#ove structure ontroll first enter into the
initialiAation part.+e3t check for the result of the
condition( if it is true it will e3ecutes the
statements.+e3t it moves to the /ncrK8ecr position and
again check for the result of the condition if it is true
agian it e3ecute the statements.This procedure will
continue until the given condition is false.
L wap to print the n natural num#ers.
L write a program to print mathamatical ta#le for a
given num#er
Lwap to print even num#ers in given range of num#ers.
Lwap to print factors of the given num#er and find
whether it is prime or not.
+ested )or:-
if a for loop is given with another for loop is called as
nested for
eg:-
for4iT1OiMTnOi..)
E
for4ZT1OZMTmOZ..)
statemetnsO
F
here the statements are e3ecuted for mLn num#er of
times.
Lwap to print mathematical ta#le.
Lwap to print following design
L
LL
LLL
LLLL
while4):-
structure:-
while4condition)
E
statementsO
F
/n the a#ove structure compiler check for the result of
the condition if it is true then it e3ecute the statements
again check for the result of the condition if it is true
again it e3ecute the statements.This procedure will
continue until the given condition is false.
Lwap to print the n natural num#ers.
main4)
E
int n(iO
clrscr4)O
printf4P$nter an! +um#erP)O
scanf4PSdP(0n)O
iT1O
while4iMTn)
E
printf4PSdQtP(i)O
i..O
F
getch4)O
F
Lwap to find the given num#er is perfect or not.
Lwap to find the factorial of the given num#er.
Lwap to print the given num#er in reverse order and
find whether it is pollindrome or not.
do..while4):-
structure:-
do
E
statementsO
Fwhile4condition)O
in the a#ove structure for first time the statements are
e3ecuted with out an! condition.+e3t it check for the
result of the condition if it is true again it e3ecute the
statements .This procedure will continue until the given
condition is false.
points to remem#er:-
1)A do..while statement is end with semicolon4O)
2)The condition is given at ending level.
:))or single statement or for multiple staements
#oundaries are compalser!.
Lwap to print the n natural num#ers.
GincludeMstdio.hN
GincludeMconio.hN
main4)
E
int n(iO
clrscr4)O
printf4P$nter n valueP)O
scanf4PSdP(0n)O
iT1O
do
E
printf4PSdQtP(i)O
i..O
Fwhile4iMTn)O
getch4)O
F
Lwap tp print the n natural num#ers in page wise.
Arra!s:-
According to user program he has to declare no.of
Raria#les. this is a pro#lem to the user to access those
varia#les in the program this will produce comple3it! of
the program. To avoid this user has to implement
arra!s concept.
An arra! is a group of similar data elements. Arra!
store num#er of values. To access the arra! elements we
have to su#script reference.
T!pes of Arra!s:-
1)single dimensional arra!s
2)8ou#le dimensional arra!s
:)-ulti dimensional arra!s
1)single dimensional arra!:-
/n this t!pe of arra! we can store the values in a single
dimension that is linearl!.
s!n:-
datat!pe Arra!YnameCsiAeDO
eg:-
int aC<DO
we can store < values .
L wap to accept 1B values into an arra! and print them
Lwap to accept the n values into an arra! and print
their sum and average..
Lwap accept the n values into an arra! and find #ig
num#er in the arra!.
Lwap to find whether the searching element is found or
not in an arra!.4linear search)
write a program to arrange the values of the arra! in
ascending order.4'u##le sort)
2)8ou#le dimensional arra!s
/n this t!pe of arra! we can store the values in two
dimensions
that is in matri3 form.
s!n:-
dataYt!pe Arra!YnameCsiAe1DCsiAe2DO
eg:-
int aC:DC:DO
we can store 6 values.
wap to accept 6 values in to dou#le dimension arra! and
print them in -atri3 )orm
wap to print the traspose matri3 of given matri3.
wap to calculate the sum of the diagonal matri3 and
print it.
CBB B1 B2DCBB B1 B2D
C1B 11 12DC1B 11 12D
C2B 21 22DC2B 21 22D
aC:DC:D(#C:DC:D(cC:DC:D
cCiDCZDTaCiDCZD.#CiDCZDO
cCiDCZDTaCiDCZD-#CiDCZDO
wap to print upper triangle matri3 and lower triangle
matri3
wap to calculate the sum of the given two matri3
-:Pointers:-
/n previous programs we access the varia#les through
its name or identifier( #ut to access these varia#les
through its address is the concept of pointers.we note
that a varia#le can not assings address of the other
varia#les.There is one and onl! one varia#le that can
holds the address of the other varia#les that is pointer
varia#le.Allwa!s a pointer varia#le prefi3ed with P L P.
1)8eclaring a pointer varia#le
int LvarO
2)Assigning adress of the other varia#les
int a(LpO
pT0aO
:)Access the pointer varia#le
i)To print the value PLpPO
ii)To print the assinged address PpP
1)wap to implement the pointers concept
2)wap to calculate sum using pointers
:)swap the 2 values using pointers
;)wap to implement the pointers concept with arra!s.
Strings
A string is defined as group of characters and it is
single dimensional character arra! .sometimes user
needs to manipulate with the strings for this purpose
there are several strings functions are availa#le in a
header file called Pstring .hP.
Ldeclaring a string in the program
char strYnameCsiAeDO
eg:-
char nameC1BDO
wap to print given string
some of the availa#le string functions are
1)strlen4):-this function returns string length
s!n:-
strlen4string1)O
2)strcmp4):-ompares the 2 strings
s!n:-
strcmp4string1(string2)O
if string1TTstring2 then it returns B
if string1Nstring2 then it returns 1
if string1Mstring2 then it returns -1
:)strcp!4):-
th is function copies second string into the
first string
s!n:-
strcp!4string1(string2)O
;)strlwr4):-
this function returns given string in lower case letters
s!n:-
strlwr4string1)O
<)strupr4):-
this function returns given string in upper case letters
s!n:-
strupr4string1)O
=)strcat4):-
this function adds the 2 strings
s!n:-
strcat4string1(string2)O
7)strrev4):-
this function reverse the given string.
s!n:-
strrev4string)O
1)wap to print the given string in lower case(upper
case(reverse order and its length.
2)wap to find whether the given string is pollindrome
or not .
+ote:-
Allwa!s a string can #e end with a null character.it is
indecated #! JQBJ.
:)wap to print the length of the given string and print it
in reverse order
with out using string functions.
;)wap to find whether the given string is pollindrome or
not with out using string functions.
<)wap to print the given string in lower case letters and
upper case letters with out using string functions.
=)wap to print the AS// s!m#ols
)unctions:-
A function is a su#program with set of statemets to do a
specific task. allows user to define and design his own
functions.
To implement functions concept
we have to follow following : steps
1)8eclaration of function will #e at declaration section
that is #efore main section
s!n:-
returnYt!pe )unYname4arguments)O
2)oading part of the function will #e at su# program
section that is after main.
s!n:-
returnYt!pe )unYname4arguments)
E
functon #od!O
return valueO
F
:)alling of the function will #e in the main section
s!n:-
)unYname4arguments)O
return t!pe:-
*eturn t!pe is the data t!pe that is which t!pe of value
the function can return.
)unYname:-
To identif! or to access this function a suita#ale name is
given for it is known as )unction name.
arguments:-
Argumetns are nothing #ut varia#les that can invoke
the funtion in the main program.
)uncton #od!:-
$3ecuta#le statements of the function given as function
#od!.
return value:-
After the e3ecution of the function the final result can
#e given as return value.
local varia#le:-
A varia#le which is declared with in the #oundaries and
that can accessa#le with in the #oundaries onl! ( is
called as local varia#le.
1lo#al varia#le:-
A varia#le which accessa#le at an! where in the
program is called 1lo#al varia#le.
1)wap to implement the functions concept and print
message as PThis is )unctions onceptP.
2)wap to calculate the addition of the 2 values using
functions concept
:)wap to print the mathematical ta#le for given
num#er.
using functions concept.
;)wap to print the factorial of the given num#er and
return the result.
<)wap to calculate the simple interest .
=)wap to print #ig num#er.
call #! value:-
all the function #! values of the varia#les is called as
Pcall #! valueP.
eg:-
the previousl! discussed programs in functions concept
are all e3amples for Pcall #! valueP
call #! reference:-
all the function #! address of the varia#les is called as
call #! reference.
eg:-
Lwap to swap the given 2 values using call #! reference.
Lwap to pass the arra! values to a function.
-:Structures:-
A structure is a secondar! data t!pe and it also
considered as user diffident datat!pe that can
s!nchroniAe or group the primar! data t!pes such as
int(float(char(........
9sing this structures we can maintain the records.To
declare a structure we have to use a ke! word called
PstructP.The declaration will #e in declaration section.
s!n:-
struct structYname
E
datat!pe1 ele1O
datat!pe2 ele2O
..........................
FO
8eclaring a structure varia#le
struct structYname structYvarO
Acessing Structure elements:-
structYvar.ele1O
eg:-
1)8eclaring a structure for student details
struct student
E
int rnoO
float feeO
FO
2)8eclaring a structure varia#le
struct student recO
:)Accessing student elementsO
rec.rnoT12:;O
rec.feeT7<BBO
1)wap to implement structure concept
2)wap to calculate the student results using structures
concept.
Points To remem#er:-
1)A structure varia#le can occup! the siAe as the total of
siAe of structure elements.
2)A structure works same like as single dimensional
arra!.
:)wap to print the siAe of the given structure.
;)wap to print the arra! values and accept the values in
to arra! at the time of declaration.
<)wap to prove structure works like an arra!.
=)wap to implement structures concept with functions.
7)wap to implement structures concept with arra!s.
-:)iles:-
A file is a collection of information.He can also create
the files using c programming and store the information
on specified file.To implement this concept we have to
declare a file pointer.
declaring a file pointer:-
)/"$ LfpO
To open a file following statement is used
fpTfopen4PfilenameP(PmodeP)O
To close a file:-
fclose4fp)O
8ifferent t!pes of file modes:-
r ----Nto open a file in read mode and to read the
information
w -----NTo open a file to write mode and write
information on to a file.
a -----NTo open a file in append mode and to e3tend the
information of a file.
T!pes of files:-
There are : t!pes of files
1)te3t files
2)se2uensional files
:)*andom files
putc4):-
this function puts a character on to a specified file.
s!n:-
putc4charYvar(fp)
getc4):-
this function gets a character from a specified file.
s!n:-
charYvarTgetc4fp)O
$&):-
this ke! word indicates the end of the file.
Lwap to create a te3t file
Lwap to read the information of a te3t file called
te3t1.t3t and count the no.of characters(no.of
occurrences of JaJ.
Lwap to read the information of a file and accept the file
name at run time.
fprintf4):-
This function is used to print the formatted oKpJs on to a
specified file.
s!n:-
fprintf4filepointer(Pformat stringsP(varia#les)O
fscanf4):-
This function is used accept the information of the
specified file in to the respective varia#les.
s!n:-
fscanf4filepointer(Pformat stringsP(address of
the varia#les)O
feof4):-This function states that the se2uensional file or
random file is at end position or not.
if file is at end position then it returns true41)
if file is not at end position then it returns false4B)
s!n:-
feof4filepointer)
Lwap to create a se2uensional file.
Lwap to read a se2uensional file called Pstud.datP.
Lwap to displa! the records of a student of a file called
Pstud.datP of given rno
fread4):-
This function is used to read the information of a
specified random file record #! record.
s!n:-
fread40structYvar(siAeof4structYvar)(no.ofstructures(file
pointer)O
fwrite4):-
This function is used to write the information on to a
specified random file record #! record.
s!n:-
fwrite40structYvar(siAeof4structYvar)(no.ofstructures(fil
epointer)O
Lwap to create random file to store the product details
Lwap to read the random file called prod.dat record #!
record
Lwap to demo on colors in .
Lwap to create the window.
Lwap to create a smile face.

S-ar putea să vă placă și