C 1
C 1
PROGRAMMLWG
Done By
NAME:P.DHARSHAN
REG No 2109 24 20Soll
DEPT.' 1T (yeav)
Write a Cprogram to genevate he fivst n umbers
in a Fibonaci Series Fod
Find he Fac toral of a
9iven umbey, check 1F palindrome
and check whether a iven tnteger
yea is a leap year ox
not
PRDonRAM
#include/$tdio h
lFunc Ron to generate e Fvst n unbes in Whe iborac
bomsd
Sevies void qeneate Fibonacci (int n)
int a=D,b=|.next
pint F(Rbonacct 8evi es")
For (Sotiso,ien ;it+ ){
fF CT==o)
pirtFtd ",a);
else tf (i==)
printf ("hd", b);
else
next a+b,
a=b,
b next
pinltd",next);
ptntf("n)
Yetxn Fact,
jump
H check8 each One tables
Seqpenally
No explle ft beak Reqates break to
SHEMENI heeded,a cond fion8 Ptevert Fall
Re QUEENe Tndependen to
Subsequent (ae
DEFOULT
(Ase
USe3 elae for
uses de faul! for
hardlng
AANDAINO CAses Unmatched handling Unmatched
Cases
pnt F(Tuo\n).
beak ;
Case 3
Pinf(vee \n"):
deFault :
pintt(oikex number\n')
3
Snt maint)¬
Tnt num';
pitF bEnter a
ScanF ( d", &numhumber:):
):
usnaf eke (rum );
usng SuitchCase (nun)
vetm O,
OUTPUT
Enter
anumber:2
sinq 1f - else adder: Two
Sutch- Case Two
-plain e vaoua looplng 3otemen aydloble
PPoriote arnle
looping o Mecative iotereert Caytes
Lalements Cor Cormpourd 8ale rmente) o be eoslod
peatetly ntl le Specitrod CondT ltr berormot
do hile bop
an
entg (ond oMod oping 3tatomeht
* Aalement: oxented
while con ditton % due epeatedy
yntax
whfle Ccondi Pon)
Statemen ts
Sncement ldeCrement;
FLOWCHART
CoNDITION False
True
Inctement /
Decxement Tiue statement
Example:#ncudestdio h
int mainc ){
pint f("\n"),
e uno:
UruT
Numbe 8 From | to j0:
I23 45 6 78 9 10
2do-while loop
is an exît ontrolled
loop?ng statement
Lt ?8 used to exeoute a 8et oF statement S
epe atedly wntl he logeal test tesults become
false . This is ealed we post -test lbop.
Because, he test FoT Yepe PHon î6 made at
Hae end of each pas
* The do-while loop Chekg its eond? fon at
Hhe botom of he loop Whereaj Fox and
wh?le loo p8, he loop cond? Pon ?s chec ked
at he top of he loop.
do
8tateme nts:
Ynccement /dete ment)
while Ceondifon):
Flowchavt
ncrement/
Deciement True 3 tatement
True
CondHon
False
Ex:
#ncude stdio.h>
nt main (){
Éint num = ,
do
pint f (u "/ d",num ):
numtt
while (num<=s):
pint f(\n");
re turn 0:,
OUT PUT:
I23 45
3 FoR looP
+ Tt Ts an
entry Contro le d bopi ng Statement
Execut es a Seque nce o¬
of Statements muple
Hme and abbreviates he eode at
he loop variable manage
For lo op S+ructure ,more
Varfable Can be
han one
?nial ze d
more
hat Conc?se and lexible han
wh?le and do- while loops.
*For 5tate ment
3hould not end wî B temicolon
SynTAN
fo
(in?talizafon ,test - Condîfon ; încsenert/
decce ment
Statemnerts ,
Advantaqes
* More ConcTse and
and Easy to uge
Flexible
More Wran one varíable be
TnfRalized
More han Ohe ncre ment lan be
applfed
More Ran one CondiHons Can b Se.
FowcHART
Tnitializa fon
Expye ss Pon
TEsT False
CoNDMON ExT FoY lbop
TYue
Body oF he loop
nerement /
Decxe ment
Exnmple
#+încude 2stio-h>
9nt mainC)
prfntF CNumbers From I to lo:\n);
Fov Cintf=l;i=10,i++)
pf nt FC ", i):
pr? nt f( n");
Ye turn 0;
OUTPUT
Numbets From to 10:
I 2 3 45 6 78 9 I0
(onipilaion.
of he
ipevtant
dnee Ave3 Snclude
+ The 9ncude d?recHve
?rer Hve s usod to tell be
pre proce ss fnq What we rneed nfotrna on
fom Be ge lecied hbay f7le known a3
hea der (le
* The # delfne ?s also he
pre poces30r d?vec Pve T Commonly
agsigns
uged
Constant vaue to he gym bo lic Constant
SyNTex#?ncde stondard header ffle >
ExAMAE #Pncude Lstdioh>
+incude math
SyNTAX #de fine Name Vaue
ExAMP2E # de Fne MAX 100
3DEF (NITION
* Pre
PoceesoSStarts wi th he
*#defirne preprocessor fs used toSymbo)
a Constant Cteate
* Whenever hroughout he pogms.
name 13
Re achual piece of replaces by
defined Code
Exomple:
de Fine Max 100
4 GnloBAL DECLARATION
dec lafing he variables outside oF all
* By made accesgfble to all funta
func ffons, Jhey can be
în Me progvams. Sach vatlable &
are known
variakbl es
gloal
* The gobal declara fon Jec Hons Cortain
vaia bles. funcfo declaxalPon and stae varables.
* Varfables and fure ons which are delaed
n scope Can be
used angnahee me pogarn
Exampleint nm 18;
pfntf( Sum =
`umly)):
Snt sum Cint y
tetusn
OUTPUT;
Sum =7o
he Various dta ypes yporte d by ha
5 Explain
are
oF d?Efevent
deelarha Variables oN fune on8
much
of a Vayîable deter mineS how Space
Hhe bit
and ow patten
upies în stoage
is intepreted
DATA TyPES
cha a,
Char azC:
Toint Data
oatirg point data type onsíss of
2. do uble
* float data ype
byre allous a vaiabl to stove
desimal yaues
3tocage
Hhe
Storage size
(har
nsigned chay
Tbyte
ned char
byte
flsat a
Cloat a=3,4
oueLE
+Dauble data type s
also 8ame Float data type
as
allous upto 15 digi ts after
+1he Yange For double decimal.
îE +37 datahye îs From 1E -37 to
Otcuptes
Range
8 bytes 9n
memony
:7e-38 to 7e+ 3 o8
Stoxage size
Fioat 4 byte
19ble
ira double
1o byte
double
SECONDARr DATA TyPE
aUser de fned data ype
în addiHon to Hhe stmple data hyes Such
as nteaer, Float : Char.etc, c' allous he Wse r
to declare new data hypes Called user- defined dat
4ypes These data types Can be deelared withhe
kelp of keywords called ypedef and enumeroted
Cenum)
Type def :
în c, keywor d Called ype def ?s used
data tpe a new name to g've a
SyTAK.
bype def < type >datanames,
Ex:
False:,
tue;
enun Boolean check
Heve a Vayiable check s oF enum boolean
3. Void
The void ture 8pecities hat no value îs availak
t is used în Rvee kinds OF
Situa on
() Func Pon re tuns as
Vod
A func Hon w) h ho
veuin Vaue has he
rehun type Ex
void.