0 ratings0% found this document useful (0 votes) 56 views24 pagesC Programming Notes Part 2
c programming notes mechanical engineering semester 1 part 2
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
Types of logical openators:-
logical AND
logical oR
— logical NoT
'@ gb &Reca)
Jot Cnot zero)
1231150
TN’ 21 (Asctt no. Value) =o
Jo-3
Jogen
G d-ge 1-1-1
JE Ci¢a) =" Crotigy = War=lo=4
Logical spereatore. (ns) 8 &
=> In case of logical and, if and only &f both the operands
tperrators ane true, then the Value of the expression
is Hrue (0) or else it is false ¢ p.eh=‘N’
int x2t,y=2, 273
a xhSyet SGRR2) 223 =(1 201) £83
a1 R23
ney &Ry>D"O Va
a Pe 21%81
1
=t
= (ga) & 8 &>2)
=1a60
=o
Logical of (0
=D In case of Logical of, if the first operand \o 1, than
1+ wil) not work with the second eperater opetrand. IE
will Gost give output t.1F the 4° operand is 0, then
if wilh work with the second operand.
a Wy &&L—staieh freom left!
Tuy Yybr ei a2 22 ro RBA «OUT RHR
1 2/@Ba = 1822 2X22 =O KER
ry eT RQ al =o
21 =4sin oli,
AND oR
pay 1 bo
| 0 © 1
° | oO 0G
0 6 ° °
int x= O,y 0,250;
int azo, b=0,cr 05
Printé C" & <2 8G =o) &8Q=3)2 %d\n", cua) 82
RE ys 223 i G2) RE @ =3);)
print} C" x= “dy Kaz has" wy2)5
X=, ¥r 0,220
*|primt$ ("@ a1) RZ bX R(era)=%d” Get) RELKA Cees)
asl, b= 0, to
printf C"@ Abed, cr % db") asbedy
HRE01Y20, 270
print C' Xx I MGra) N29 Za" GeDNG=ayN@-a))5
xe by yro, 270
puntf CO" x= *dys Ad e224" wy2)5_** Assignment Operators —
op=exp. an = ty!
aa opeenp a ean Ca ty-10)
at =Qry-10)
@+4+=10, 2=a410
a=at(xty-to)
Q-=10, a> a-I0
iz =10
i = tT
Increment Operator (++, --)
amen Ope kee
ttm > memal int a,b
wag, oemeder’ a= b+105
atts
-- m3 mem-4
3 msm25-08-2019
do
{ printf (“|nput number "}
number = getnumber C);
|}
| while Cnumber So);
sum=sum4 5
|
whie Covmy Goll sum digg)
a)
=> Do statement execuks at least| Loops'~ NESTING
while, do, if, else AP-IBUSE
fees
flow chant of if statement:
(Enter)
has,
/ test - Ente
AS, [ase | ®
—1
(Te)
(if staterrent) |
Thue
|. se }
if etse Aone | atecoei
hack
if Ctest expressson) | ia
| -
ta . stat
| 3 fae statements) von — __I
3
else £ false statement ;
3
| ig Cord t= 0)
| Grater (float) Cath) tock) (ers);
printf C"saho= AF NN ", vako),
}
else Spek
printf ("esd =oNn ");nesting if else
Nesting if else if Chee)
: if Clea)
if Ctest condition) f /
{if fest c-3)
le
if (lest condin on=2) ties}
else
| {At Gest condihon-3) Gatat ty
{stats 3} 3
else else
Lstatead ee
| :
| etse es
stat: 54
3
else
tstat:e}Nesting if ebse flow thant
+ if Cpersen is female)
Lif Cvolence >100000
bonus= 605 balances,
else
bonus>' 0:0) botance 5
3
else
} bonvs = 0-024 balance,
ja4
Wf (person is female) ey
. dangling ef if-else.
If (balance > to0d000)
bonu
05 & balance ;
tise bonus = o:oQH balance
| balance =balance + bonus;
| angling else if
aelse if ladder
if Ccond=1)
st-15
else if Ceond-a)
St-25
else if Ccond-3) \ evse if
st-3; ladder,
| else if (cond-n)
| stn;
Weise
| no longes SF, becavse no further
the end.
conditiins ave there at0-100 > At
To- 745A
60-40 38
40-4 FD
#H include
int man ()
{
Ink mark 4
printf (“Entec a grade: ");
scanf ("Ad") Bmarkds
if Crnark <= 100 22 mayicS= 0)
PTINkf C" Gyade ADS
else if (mark £94 b% mask>= 70)
printf C" Gade nD)
else if (mark <= 702% mark >= 60)
printf (" @rade B")5
else af (mark 2-59 &B Mark P= 50)
printe(" grade 0"
cise if (mark C247 RR mAek 7 49)
prin f C’@rode 0 ")5
else fprintf C" Fait "))}
Vehin 6~
]
es)
(s32]
| for Cinihaligzations con dition, increment /decvement )
| 1. body of the l0oP
if | write the same
3 statement with while Loop:~
Jae > increment part int x= 4)
white (x >)
y prints Cad An's, Hd
for (x= Q5 x05 ERE newts
| L printf Choad) WO, %
———— WITH Do WHILE
i--— decrement part
printf C\n")5
*=4
do
g pvintt ("Za \P"> w°,
| weutd
while Cryo)sum=05
ce Cn=1y n20 && sumcioo s444i3
1D togica epenaty can also be used as @ Condihon.
t
3
Jo
n=0, sifthe value of Hhe Variable
ox jneaay js declabed earlier, Initialization,
{nena con be emply
\ if incr. /decr. js stated eoly,
|| i+ can be empiy-
l| + bu the bods—ef the Loop
Most contain semi colon
“Semicolon MvsT be there im
for Voor
717 SEE EXAMPLES OF POR ip EFRON scHAUN SERIESSwitch STATEMENT
aL
—— _Carorks like else if ladder )
switch (expression)
|| case value-I: ‘blank-15
| brealcs general
| case value-a blank-3} syntax of
| break: swileh ofate ment-
| defautt: defavlt block;
| break§; J} st-Kyz;08/04/2019
Enivy
expression- 4
cs
block 1
aaa
exeression-alyi ony 2
ona) oe
x pression-3
block 3 [| +? stot v
Index=mark/{0;
5wi teh (inde x)
a
[case 10%
case 4
tose &%
} grades “As 5
break;
Cast Fi
case 6+
grades“ O+'5
be break;case oS.
grade= C4’,
|. te
|case 4
| grade = «p's
| breaks,
(tose
‘default
|| Grade = “¢giy)
break;
,
prints CN, s.\n ”
| ,
|
R for loop’
grade);
used to cheek the atrade of many students
*+ im one program,
| Go to Statement
| ~ So Aaeee
| place,
> G0 1 Statement requines « label to identify the ‘plone
| where the branch is to be -tsed made,
Jt, (abel is a mame ané must be fottowed by a colon.
|The labe) ‘> placed immediately before he statement
|
|
Whede the contizol is to be tteansfermed,=> label can be before the go fo statement then it is
Fcatied back ward jump.
Again,label can be aftes the go to statement then 3 is called
forward sump.
forward
ea ke wand
| to |label |? bas
| got [tab &
| labels
[stetemen}_blocls
statement diock
CD) (labels go to label.
state ment block
|
i
}
CODE CIN FINITE Loos)
int main ©)
| double 4 5
|| read:
| scant (AE RW;
| (x 68) yebectwons ge fe reads
Y get=sqrt Cx)
PALER, prime ZbA0", Gu)
{go te read |~ 5 this go te read at the end will
I} cause the progam to yun confinvossiy,
|Pare
while) ise) as elbane’ Ren the! ahi:
Ail Crag as) loop
breaks,
ao .
tor C9
Lifer ()
bie (cond:
break;
while C)
i
VF Cersor)
90 to step;
if Condition) °
go to abe;for ¢ )
t
by COR aa
| Lit Condition)
[ae te enon
}
| }
errors
just like breke Lbyeak , continue is also a statement.
For continoe, program will conhnve7
es RS
s ce [Area ] SS
OT ee ae of data,
= * Access values with huge volul
Ariay
Il ed collection of
“PAN avvay is a fixed sized sequenc
j 1
|| Slements of the same data types. I 18 simply a
| SRrouping of Tike type data.
$n is used
||
to express a list of Mumbers, list of Products,
Array [
“Ul
Catted index /sob-ceri bk
used ty determine the
Fem. Clo] clement
7 4emp. 0, 1,
clement sire
clement sire
2,3,45 Y 8,9
Wf the ankay is at the beginning
act asa declaration.
total numbe y of
used d to determine He Lelement si20 then Cif
declared at first),
temp C100] (0 to 99 elements)
51<1005 ia)
{
]
| 4 pvinf C* Enter 9 femp.:’)sAicrays ae of the following types:
* Dne dimensional array
“Tao dimensional atray
“Three dimensional array.
One dimensional array:
SDA list of items can be given one vaviable name
. i called
Using only one subscript and such a variable
a one dimensional a vray.
ne Cog sbla 02, 17 O09 - ule]
Uhow fo declare an arrays
| type array bre]
int afi] / fiat alic) J char olto)
" for chairactes type airiray,
sa is an asray ’
we can declare a, shiing,
shas 10 elements
‘all the elemenls has integers.fr
— becavee alt shy
a0=l,a\=2,a4e3
int als]s= {12,33
met ayer oe
Un implies that: + sobsctiip! can be empty.
+The no. of elements declared
was will be the no. of elements in
the so bsctript-
“bot, an the elements shold be
declared shen.
tOretse
thay al 5 ]=gty’, ADA Ly
oy
char af j= UNA yy Ay
| by defaust, the computer will -Lnderstand
o C5) vserr.
“bot, If you declare this in @ sting
>
ated
“ings have a poy charactey
Cthat we de noi cee)char aleJ= in’
Since only one svt of 6 characters have been
Tdecianed, the vest of jhe 5 chanactess ill be asevmed
fo be null characters by the compvtey.
| for Ciz ty i ct00s +41)
© eG c50)"
\ sumli} = 0;
aise somUiy=s;
Gobto ebb
ens 4) 45 » ”Wdouble averages
int mavk C50] 5
inky, count, Sore 5 ;
For (Val id= 505441) soreda tun
{
Prine ("Enter the mark: ")s
scant ("Ad", & mark);
t
som = 04 ‘ 1
for Ccount = 0; Count ¢ = 50544 Count)
t
SLM = Som 4 marke j
averrage = sum £504
Print C" Averages %a-dif", average )5
yeturn 0%| ink main
t
“int avg, sum= 05
“int i
Int—mein
ink markslsols,
| «og Ms
| for ( feo; i<=eesi70)
ls
| scant C'% a", & marksCid);
3
For Ci= 05 7K =443 44)
3 som = sum4 mark)
avg = 90m /505
|
\|s
printf (* avg> “4 " avg)?
aeforn %