0 ratings0% found this document useful (0 votes) 94 views41 pagesC Language Notes-1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
—Aigousthn
[Start step 1: Stavt
‘Prpat —
|
step 3: ce ath
“Ceocess step us paint c
[ecart |
J L
Outpul step 5 i stop [eine]
J
(Step /
rea and Ciscumfevence of Circle
Algexithm
input 2 staxt
process 7 ae Ske TET
Ce De BHT
output $C> Draw « flowchart to tput bosi
input bosic aalary and caleutal,
alate the Fetouing «
© HRA = to-/. of basic salary
* cca = 20-f. of basic salary
© DA = 30°/- of basic salasy
Coleulate the total calary of on employee
basicsal.
put
HRA & 10/t00 * basicral.
:
+ Loe
teh & 20(100 basicsal,
* bosicsal
process >
DA € 3o/iov
total € basicsal + HRA + cch +DA
output > paint otal,
Law dort
[roeed osiest]
_—T
HRA tofroof basiesal [rere het |
cae of 105" basica, . “fo
on e Bel ed bshesel [ene mle® Suan
otal boss + HEB ecp+DA a
Jo [ pe <3 sf *haxicsad ]
print total.
| folal — daricsal + ARA4ccnt op)
ee ere; y
3 12-Aug-2072
> plgevithm —> 3 types of statements
1
t. Sequential statements
Selection | Conditional statements
tatements .
“ee
ui Pteaative SI
Selectfon [ Condttionah et te ee
En these statements, we use
> tf-else statement °
= whee We Weve dum epbene cud wced to aclect
and execute omly one -Structuse %
te < eondftion> then
rues block statements
else
Ealse — block statements,
Flow chaxt °
true-block sty:
statement *
© latte am algorithm and claw flowshart to Limd
wthether the given mumben 1s even ov eda :
Algorithm * le Stat
2. Reat 7
3B 2B m2 =0
Ba pent “6 bee”
el. path ven number
a. else
4 paint “odd umber”
: §. Stop4 lowchort : staxt
print “even norben paimt “odd murnber }
# watte on algorithm and dvaw a flow chast te nd
gzeatect mumber among theee
Algorithm 2 te Start a ae
- : b eA ls
Qe Read a,bré eee .
, e i gveala
3. te a>b then . b
cingrveaten
mal te 2c then
a y
Bet paint oe i greatest,
goo else :
B21 parnt “aes greatest :
ue else
tot TE b>e then
lett patnt “bt greatest”
u-2 else
° u : u
isaet paint “cis greatest
5+ stopLlowchart to Lind sf displacement
© wivite an alegovithm,
fos the given values of ust, 6, a -
B La
ut + Gat
Algosithm : Step |.* Stavt’
Step 2! Read u,t,a values
Step 3 + [s curt thx axt« 4]
compute dli’splacement waluc S
Step + pairk s vatuc
steps 7 Stop-Flowchaxt |
e waite an algostthm, flowchor
L-lo check whether -
given mumber ts positive no: oF pmegative ne:
Algorithm + Step t Stavt:
Step 2 ¢ Read m value
Step 3° te moo then
sep Set print “positive mumber”
step 4 : else
Step uel
Step & + Stop
yt
v ° ”
pant ‘megative mum beElowchovt +
{> > |
/ forint * positive m umber” ‘ive mumbes” | J eins “megetive mumbo” f
© wisite am algorithm, flowchart to check whetbes the
number is Atvisible by 5 and 3.
Algorithm: Step Stavt
Step 2: Read m
Step 8 ¢ 2 (mS =0) then
sets U2 (me/-B=0) then
3228 print “mo. is divisible
by § and 37°
3-2: elce
3-261 print “mor ts divistbleby
5 andnotby”Step 4 t else
if (n¢/- 30= 0) then
3 and hot
ule
Yelel ¢ paint “no. i divisible by
Ly se
4.2% else
“no. tg not divisible by F
Herel s paint
”
and 5
stop
step 5 *
Dowchast :
print Sno. is
not divisibl. by
6 aud 3"
prink “no: és
diuicible by 3
butnot by 8”
print “no. &
divistble by $
and not by 3
Print “no
dfuistble by Sanda]Write a C program to find the sum of two numbers
He Taclde .
Snt mein 0) :
int a=i0,b=20,c7
exaths
Print (ica 6)
retusn O;
’
westte a C program to find: the Grea of circde «
\
th include
fad auaus 0)
f
fleet c+ 26-8, 7
Pe Q/seet82;
printf C'%E", €);
pebuan 0;
Psevno Cove
© Pseudo cocle ts a simple way of voriting gregremming
Cocle tn English.
}
Pseuclo code is a detailed yet readable description of
uathat a ee Cregram or algorithm oust ae)
expressed in a formally — styled natural tanguag e.
rather than in a programming language
Pseucto code. is am axtiftctat and tmformal language
that helps programmers to develop algor?thmsCeample +
Pseuclo coce
?
Tnput a set o& 4 marks
Cateulals their average by Summing and dividing by
4
TR average %s below 60
print “ Fatt”
else
print “ Cass”
Structure oe C CRogeAM
| processor | > treluds & statiosh>d
- | . *
main module —s nt man
7
it ' {
l
|
Seclaralion = tt ¥ =t0, y= 20,25
| @xeeulion or body) —s Bexty ;
i } : prink® Cv." 2) -Dectaratton (variabl @ declawation)
Syntax 1 datatype variable_name +
example : tnt x,y7
Lloat 2 5
fn declaration, Memory is allocated to Vortable . ,
Rvtes To Dectare A Unetnece
A variable name canbe combihdlion of alphabets and
numbers +
TE chould begin vith an alphabet or cpectal character
unclerscowe- Other than — , ho other special chavacters
are allow ed
nlo spaces are allowed +
Valid | © Not valid X
. fnt ac
tnt —xyey
le int simple inte »
int a¢ : ’ P aSean€ ()
syntax: scant ("formed specifier”, Svart ; vor?) ¢
Cauple:
Ht tucluds
fat mod
{
int ys
prind® ("Erb auy-toomuubars :");
seant (" frol-bd * 9x,9y);
z= uty
PEC dh ae
“PRoGRAMS
* Gopal spends time on problem solving - tle golves
one problem on first day , on second clay he
Solves 2 more than best day count and soon
Eend the uankey vf problems solued oman
day -T¢ he takes p mins to solve each problem |
fimd the total hours he spent on the pre blem
Solving th thet emonth .day! —> 1
day 2 3
day z— 4 formula : ( n-0"p) ho
J
'
dayn — 2n-!
HEinclud@ ¢ stdio-h>
tmE main)
{
int;
float p, Hme_hbrs 5
Seont ("efed 0", BO FPLE
time—hrs = ((2%-1) +p) /eo;
print ( “#8”, time hve) 5
return Ds
Ravi's livelyhood depends 3n Selling groceries everyday he
brings p gallons of ef! from his village “to vaddeswaran,
M vadeleswaram , he ‘aipplies 2 Ittres of of! to each
of 50 households . Pind the: nov of Itres of off leet:
with him.
[t gallon = 3.385 tres ]A tnclude ¢ stdiosh>
fink main ()
Float x, leet_over ;
sean (“e/-0", x) 7 ‘
% =x * 3.786 ;
left_over = (x - 100) 3
prénte ("9/-€" teet_ over) ¢
retusn 0;
(oR) Te noo households & mn”
At include
Tat main (J
{
float x, lebt over ¢
tnt m_house |
sean€ (“e/eRe/ed” x, dn—house)-s
x= x * 3.996;
left — over “(* = (-house *2)) >
printf ("7 €.", feft over) -
retun 0;¥ Anshu moved to a mew house to Vijayawada rom ttyderabod
She was avvanging her things in shelves provided + She hat
o box that has moss of 125786 pounds . she I?fted the
box and placed ft on shelve. 1@ the box gatns 4s T
of potential energy how highs this shelve,
- Pe = mgh
st include < stdin.h> [
h= Pe/m*
(nt wain() ! im*s
{ [tre = 22046 pounds]
float pe,mh ;
Sean (Se/@ of" km spe) §
m= m/2.20u6 7
h= (pe/(m*¥aey) ;
print (%+/-0", h) 5
retum 0;
write a C program to check whether a gwen person is eligible
for voting ov nol:
tt onclude ¢ stdiosh>
ime main)
{
tnt age ;
Sean (“*/.d", kage) ;
18 (age >= 18)
printf (" tigible”) 2
else :
2 print (“Not etigibu") 2X Write a C program te display the name of day.
att Pncluce < stdtorh>
“Ent maint)
{
imt day -
Sean€ (8efed" ¥day )s
€ (day = = 1)
‘print (“Monday”) 3
else WW fday ==2)
print® (“tuesday "):;
else if (day=- 3)
print (“ttednesday:") *:
else & (day == 4)
printe ("thursday") ;
elseif (day=-5)
print (eiday")
dse% (day = = 6)
printf ("Saturday ") ;
dteet€ (day #3)
print€ ("Sunday") s
else
printé (" Print. not wattd-"] 5 ,2&- 08-2022
Note —_—
low level language 2 C> program
Middle levet fanguage ¢
Aligh fevel faxguoge > Jawa, python, at
key Worvs
m te a variable thot ts already axted
Darn TPES
Giving proper meaning tthe compiler,
“Weres of DATA TYPES
) Basic
2) Derived
3) Oser-defined
4) Void
Basic Datatype ( ees vive ret)
= Als called a8 primary data type.
> tnt, char, float, double, longPata typ e Size
Jou
wuss
int 2 bytes/ ubjl, %d
u Mae
char byte ” ehic
float: 4 bytes ve
double 8 bytes Yodtd
tong to bytes “ed
Periven Datatype
> Also called ay Which se defined by the wer
” €4.: erum
Voto Datatype
> The value doesnot retien anything -
Integers _, cigned inte
gen: (ave foryeue S [defout ]
rsigned ( 4ve ont ’) ~ Syntay t unsigrSreveture ot C Peogenrs
L Document Aeclion
2 Link Aeclion
3. Text Section
4. kK eeudabls Section
Peeomennt Sections
/* — / comments (single comment)
Ca : t Br multiple comments , /- a Ww]
Unc Sectwow
HE include éstdiosh>
W include ¢ conio.h> —) Courole tuput odpul +
AH include
“text Sections
vord wal)
{
ctrsr (0
printf (" tello world”) »
ged;Keown Sector
Oulput : tletlo world .
23-08 ~ 2022
* AS a payrole manager, your taut fs lo cabelas the salary of
employer given barie Aalary.
HRA = jor. of barie salary
DA= by of basic dalary
CCH = Qox/. ef bGaxic aalary
yee
\ Ay / ong
Colatal ttu total rotary of om Cmple
ab tnclude ¢ stdioh>
Emt main () 7 1G
{ oo
ftoat baric ral, hra, da, cca, total sal s >
erént€ (“enter basic Aalary : "\;
sean€ CS%C", Sbarve_ sal) »
hra = ont © bastesal ¢
da= 0-15 * basic- Sal ¢
cca = 0.2* basic sal ¢
total sal « boric ral thra + datcea y
primt€ (“total salary + %€ ”, totalaal )*
return O¢¥ write a C program that prompts the user lo enter the -follovaing
details and print them +
~» Reg no.
=> Section
> capa
> Gender
Gender is printed as single character M (mal) and F (female)
AFineluds
tnt emain ¢)
f
| long long int r ¢
imt ss
float cgpa ¢
char gender ¢
boon ¢” ofettdefed|-b ofoc” , Br, 98, Legpa, Igender) +
priate ('veltd Ledafef ee", €, 8, egpa, gender) +
return 04sl
QY-O08-Qog,
h
a
Utrite aC progrom te calculate the roots of géven
quadrat 2c equation
formutn : d= bac
rd= -b4 Jafodg
2 = -b-vd/2dy
Ak inclucte CotdiochS
tkinclude dmathsh>
tnt anand
{
int a,b, c,d, ad, %2%
print® ("€nter the coeff. of equations”);
seon€ (“*/edefed ed", Fa, 3b, ke) F
d -((b*b) - (u*a tel) ;
rf =(—b4+ sqrttd))./(2*d) +
r2 = (-b-sqrttdr) /(2* d) ;
: on ae
printf (“the roots of equatesn » Yod ancl “fs ol
72 )*
return Of* Write a C pregram ‘to cateulate the distance between two
points -
Formura ¢ d= Vf (-%,)” + Uyy-¥*
ak include < statorh>
4b imelude Cmethsh>
fmt mainW)
{
tnt ab, yl, B22 s
| printe ("enter the co-ordinates of one point”) 7
sean? (“Yede/ed", Bxt, 2yt)>
printf ("enter the co-ovdinates: of amother points") 5
| sean? (“vedyed", x2, Fy2) 7
d= sqrt (Cae) + Lys (a-90) 5
printf (“distance b/s two pants s%ed" da) *
return 0;% lite a C pregram to calewlats the Aum Oe
~ ‘n’ natural mumbers
> even mumbers
> n' edd numbers
> ff include
3 thincludk
Eat main’)
{
tnt n, re
printf ("Enter n :"):
aang ("fel”, #7)
rem*(nany
printf ("sums thd" +)
return oO;~> Ht incluce < stdio-h>
int main ()
t
int n rs
printf ("enter n=") 5
Seanf ("*/-d",9n) ;
3
tata
ventns
printf ("Sums od’, fi?
relurn 0;
28-08 - 22
C Tokens
A smallest Endividual element (or) unit:
ae Keynsords ¢ ee deere Cor) reserved word
Have 32 keywords.
int , math , float ,char, %@ y 7£-else, return
elge-il, ete.
> Tdentifiers > Name given toa variable toa funclion
Gx) to arrays .
User- defined words.Rures for ToenTiFiers
le Tdentifier mame should not start with numbers (or)
special characters .
2. Tdentifier name should start with alphabet (on
undexscore.
ees gum, gumino * : ‘
3.
Tdentiier caste sensitive.
ex: tnt a,b ¢ tnt a,b;
Cratbs vw CeAtB; X
4. Tdenti€ier mame should be minimum d & chavacters |
6 Tdentiler ust not accept seaces «
Tela
=> Strings 2 Array d characters ended with ‘\o’
character’
©
1 ar
“\o' 9 tndfccle the end of string,
fs wey es
S Pree”
oe kD char s[s];
— Constants + fied valus-
> numeric constants
* Integer
* Float -
Keyword conet’ext concd tnt acto?
conet Coat (orth 5
» String constants
tx: conet char che A 4 a character
const char ch “oan” 2 a string
> Operators 2 A symbol that performs blogic operations
atthmedic , Al 0"
Types tf Arithmetic * trerement Re
¥€ Logical decrement
* Relational * Aggigrm ent
* Conditional
+ Bkwise
4 Special.
ee: O10
\
pero op
,
> Spectal aymbols = 0, {hl te y
(
“ troy
Variable + A named memory localion to, Store Value
Value of Variable chand es
Go Saeee rules cel fete dins ey
}
Ovegntors
operand A variable or arr auf ‘or valus on eohich operation,
are performed...
“Types of operators
«© Aemmetic_op:
ERATORS
> Also called binary operators
Ft ne
|
Ti Perform eperdtions on unary , binary and ternary
Operands.
Progra:
en
at inelude
dat email) |
tte Get ball talon
: tyclaralvon eal wat bale? |
— a als
int arbp-e-ast2,b=6,¢7 * |
C= ath- |
ented)
¢-a-be
print ( Cede) :
cnatb-
printé Cted" 6) :
era/b ; '
print€ (“ta" 0)
return Os— Rerarionar Opegators
~» Aso called comparison operators
oof fe se ee
1 7e 29, FF, %
~ uted 10 compare operands
> sp given POE ition fe frae, 1 wit give 1
Te given condition is false, i will ge 0.
Program +
thinclude
tnt main 0)
i
int a=12,b= 6%
printe ( reed > Ved = Vd",a,b, a>b)-
erint € CSted eoted 22d", a,b, acb)2
print® (Crted Cad = ed", a,b, a<=b)s
print (Seed == el = thd”, a,b, a-~b)-
prnté ("eld Us ched = fd", a,b, a|=b) :
print® (Se/de=td AND, OR; NOT
olAND oR
o
|
w
B AKEKE if
- ° 6 © o
o | 0 a '
io D t . '
a ° tL | |
NoT
A 6A
° ‘
fo
Poodraun ‘ ‘of
ar tnelude < stdvo.h>
fmt main ()
t
frit atts, bos, res 7
res = (a>b) 39 (a==b) 5
print (“res 24d" res) 5
res -[(a==b) 3
print€ (“res = od", res) 2
res=! (al=b)s
print® (“ress ed", res) 3
res = (asb)|| (a==b)sprinte (“res = ed” res);
return 03
Tucrement & DecRementT OPERATORS
~ Also called as unary opesator
9 Increment by 1. atts
3 Oecrement by 1 > aay
pre-therement’ 3 +4+0.9
post -Pncremend —> att 5
=
post -tneremert
tnt wand |
{ .
int aaH ¢
printé (tasted) a) Board
printé (“azehed" att) a9"!
print€ (“a=%d", ads aes
3 Hes post ~decroment us
print é Ca ethd a--)3 a. 6
erenté (Ta= td", a) 5 ao
return 0,‘
2
pre-rcrement
tnt maint)
f
inta=n 5 wy
printl (“a= ~d" ads
ae
erint® (“anefod? t¢a)s 35 |
print? ("a= hed" a)siot cas
Pteedecrarne, /* pre-decrement 2
printe (“asd --a)s acu
Primbe (Bashy ay 0
retumo.
;
* Conpitiontar Orerntors
> dlse called af &-else control statement’
> called 4emary operators
2 var = expt 2 exp2¢ exp3
7
a te (a shy!
(arb)? (arctarc): (bse? bse)»
cio (pee Ls.
‘i
t oy
n (Soe) ) (boo)program '
uairtte a program to check whether the person is elégible for
¥} ee y
voting or nok usting conditional operator
ar fnclude i
tt main)
tnt age ; 1
Sean ("e/.4", kage) + to hother dt
Cage >= 12), 2 print® (“eltgibte ") 1 print (“not el igib’) 5
retunn 04 :
wlrete a program to Eind the largest a} three numbers .,
at include ¢ stdto+h>
emt emacn 0)
f
imt a,b,c, %3
gean€ (“Yedefed “led”, Ka, eb KC)
re (arbyt (ase ere): (beytbrc s
printe eho" aes 7.
return 05a ac program to reqel tio integers and check
te both are equol , eprint ‘Yes’ athervoise ‘No’
ae inelucle BlLutse — AND
+ denoted by & —.
> Bitwtse-OR. (1)
Jt
Bitwise- <¢, [teed
a
Gitustre —.NoT: BA (ew)
3 Gltwise->> [teght]: yD
a
Bitwise - OR awrite a C program using Lit wise operators
AP inclucle, < steltgh>
fat, paain 0
{
tnt ato, b= 6 7
printf ("a kb = fed" akb)z Lc
printf ("a/b = ta", afb)+
print (“was td "wads
réluen Ds
Brose leet-shiet L righ —sliFl
7 22te
— “ ° ro to
get
cel 2 bo oF i. eo 8
< Y»
a>r2 2 Gc 0 0 oo 00 tf O
+ Srecinr Operators {
> b,x, see fl)‘
*
te
HH tnelude 2 stdio. hd (
Ram and Rav? measure and -£ind that their houses are
50 miles aport te they agree to mect at the 'etdpornt
‘o€ them
belween thes to houtes «How far each of the
travel th kilometres -
Vo uatle ¢ 16 km
°
: . Pdléstauco'*~ go utles
AP tnetucle < stdto-hy
: 7 vay yg Lt tebistauce
dat math O eee OC
ae
imt dj wer ¢
print ("enter distance, ")5
scan€ (“o/d" kd) 5
res =(d/a)xte6 y
pried (Me74" resds
return O¢
write a C program to swap two nugmbers :
without using another variable»
Tht main (1
{
220)
tnt a,b s
print? (“enter a,b values :” »
Sean€ ( “/-4elea" Ka kb)
a= atbs ffa- 20
b= a-b: If b= 4019
‘a.
*
aza-by
print? ("eed \n 7%d\n", a,b)
return O5
with using another variable :
oft include
cut main
{
tnt 0,b, 6 3
prioté ("ter o,b valiw:”)
sean€ ("ed efed”, $a 3b);
‘ébabb®
, 4
pe ce bgt
pb = cob gui _
printé ("eed (nated ’, a,b) s
> retarn 0% '
Gudha i& Learning about C lbrary math-h function. She
found that there t a tan function in math «h header
file. She want to caleulate tan ug. aut She €inds
that tan function accepts angle only th radians -
-tlelp Sudha ‘to Convert tan 48° Coty radgans ,
ton (x) ¥ */ig0 -SE
AP include ¢ fmath+h> oo
AFinclude 2 + ;
tnt main 0
{
teat x, ds
printé (“enter angle + " y
Scan. (“ee" aX?
d= tan(x)¥ ih /t80 r
print® (“w/oe", a) >
return 0;
x A ese student plonted a tree. Eirst day the height of the
plant ‘sl tnch. the tree grows 2 inches’ everyday.
Eind the height o€ the tree én centrimetrés ‘on ith eae
eG
I thehs= 2.84 ;¢m
include < tdio.hS
fat mrs Tene
plot ("“nter height ;
“ Seanf (“%d% 90) ¢ i
r= ‘(3%y~ 1) *a.sy,
| print€( “Yat rs
return Oy+f pototer wants to paint the outer aurfare of an oil
rectangular can, Dimentions of the can are 20cm, t5em
(em. TR posse ic changed to paint per square em Pind
athe cost of painting in rupees -
2* Cf bTh* S/ioe
atinclude < stdio. hs ’
ert behah? &
tnt main ()
i
tnt & bh, C3
;
printt (enter length, breadth and height :") »
Sean€ (“deeded ", 20,%b,%h YS
C= Q™ (Rb Eb*h+h *t) ¥ S/t00;
printé (“eed c)
return 0,
Porters a
> TT holds address of another variable of, fame datatype.
7% & derived datatye + . +» . '
Syntax + datotype * var_ name +