0 ratings 0% found this document useful (0 votes) 40 views 26 pages C Programming
The document contains a series of programming exercises and questions focused on C and C++ programming concepts, including loops, functions, and variable types. It requires the reader to define terms, write code snippets, and differentiate between various programming constructs. The exercises are structured into sections with specific marks allocated for each question.
AI-enhanced title and description
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
Go to previous items Go to next items
Save c programming For Later I
}
SECTION A [24 Marks}
1. Define each of the following terms: ‘ ja martsl
(a) Loop (b) Program (c) Machine language @ Computer programming
2, Write the general syntax foreach ofthe following: 4 marks]
(do while» fanation ratty (© noe forloop (2) - “se 4 marks]
syrte «program that Wil print he following stp OM Ne areca ateees
ee or enanwnitiNc A ENGINEERING - SEC. YPAR
LOK OF ENGINEERING IN MCHANICAI
NEERING DEPARTMENT.
R PROGRAMMING
pact
MECHANICAL EN|
cS 8200 COMPU
ds “I'm the MUST
ame followed by the word l
itera layed in different
‘iteration the output is displays nae
4, Write a simple C program that will display your full n
student” 1000 times on the screen. Make sure that in eacl
Tine, Use for loop.
5. Differentiate each of the following terms:
a) While loop and Do while loop _b) Global variable and Local variable [4 marks]
"6: Write the output of the following source’e {4 markst
Hinelude
int main)
t
float num! = 4.6, num2 = 7.8, result;
‘prinif(/"This program compares 6f and
result = (num)>num2)? num I: num2;
prinif(’Where the greater number is 26f\n", result):
return 0;
j )
4
SECTION B [36 Marks}
%
7. a) Assume you have been given three array of characters which are first_name, middle_name as well
as last_name and those array were initialiged based on} ur actual names. Write a C program that
jnitials of your middle name and sumame separated by
{5 marks},
sepa", num, num2):
will display your first name followed
commas.
b) Write a C program that will converts either kilometer to meter or vice versa depending on user’s
choice. Your program should consist three functions i.e. main( ), kilo_Meter( ) and meter_Kilo( ).
Page2of3! lable ony
J from the keyboard, The wa °Plions 2. yell as prompting user to enter the required parameters
conversion opted by the use, (1s eer kil Meter or meter Kilol ) depen
: Ser an jJometer 10 0
and metet_Kil0() conveng Mice i hy results, hello Mitel ) converts Kilor 17 mack}
8.a) Write a Csource code that win ilometer. Use switch case. i fo wares
1234 Beneraterhe faltowing pattern. Use wit
12345
1234
123
12
1
© Weitea program tht wil ase any twe floating numbers from the user and caleutate (ns Sun and
\
average, [6 marks}
9. a) Write a program that prints the numbers between 20 and 99 that ean be evenly divided by 4. Also
number while statin;
your program should compute sum of the extracted numbers. Use do while loop. [6 marks]
6) Write a C program that will prompt a user to enter any integer number from the keyboard and
determine its status if the number postive a am display th
its status.
ile by 15 between 30 and 1000 exclusively.
‘The program should also calculate the sum the series. Use while loop. {6 marks}
b) Whet is the output of following source code: {6 marks}
Hinclude
int main)
inti = 8;
whilefi>=1)
f
pring("%d\t\", i);
ia
prinif(’"The odd numbers are :\
“fv? == 1)
rel Arlen,
}
pring Wn");
—
return 0; 4
3 of 3AW beeps lop camil Consists of To® padi, abel.
~p 8 loop fq tocleo| se (gee :
—P progam, Contains various funcfione Ube
—{—_____ 42 pat eps \fbra C———————-—-—-
a {tein leeguaj fle bee a machina 2
RS e, 1 he abemonfo Nenguage of = ——
4 Sompufor a
anf generf pucpare pregramining language ths)
os Feel tor fevalb ping ain cereal -
s Py lompufac peogearmming hgh level) |ataxs
1 a> geaoral sy
do
t
ytetemety (+)
J
thle (cord ition)
by Genel syahar ,
vafaen -lype furretion name (param ator lot)
1
body orth funcfion
“4
oy Cy enare|, dyntax .
for Goitalaetien: fondetion® acrement /clecroment)
{
I ser (ts Telveetten 7 tend ition , incromert/deecremect )
Jf
Sate me oT epthe inside loop
5
sTefemenT ep tle ular loopBinclads eitfro- b>
iat mala 0
t
int 9, 248,
gor (aey,ateds art)
printf 0%);
po catt A\o" \
prot (\Bactte Lor oF ENGINEERING IN M cltadicat
ENGINEERING -SEC. YeAe\n") :
peatt (OM MEctHEN cat ENG INE e104 Depa CTEM
\a’ys
' pot ( (“Cs 82. Canpotee PROGRAMM INGA)
re (Qelr ade bs att )s
; prntt’ = “5
print @\n "1,
retyum of
gBandude 4 utfie-b > _: tS ee
Jai mata’ T) é :
or
ial 4% b= Lot
Tc Iiaeabiart)
ars
5 gph 2 leop, ie Wg oo othe ol dh \ > vidhoment 2
va lh Tch the Conditien Test te petecig
_ stat the b fep.opthe | seeps
we 3
by de while lose 4 aC F. NacigaLay Mie wh! Jester
ent i 14 dich ; cond ie
te Pert evr of of tt bottom z
tho Voor -_ igor Cazliacs= =bi Sart) |
ponte CMe NOHEH BA a m n tha fe Masrefieer
tindude 2utfio sb Pues fa Mtl
Jai main C) aust Set
_| 4 — oo ;
ab _& b= 4 @o! = per aa ih :
\a7 yi
rayarn oF a fi Mae ee ot eee semeee ce
g
5: bythe Ie loop, iu te g 1g adent « eptte oh dl fe “Metem ont a
eae ulhi th the Condition faite “ perjomag
i eb ok the & fo, pepthe ac -
yee! i
oe ee
by de ult \e legis a g Sarina whi desteon-
ent i ta My ely tondifren
4 Pecferm a of tee bottom es
tho loop .5 by Gilobel vavidle, is flogi neel outa
hs ejoc,
While: 7
ey aiclle, 120 ees laclarod owe.
— 4 funcfion ocblek
Tha pregcam, Compares Fb and PE oS
Who-e fie greater number ees
ap ieeelachee tie
ley aaa og es
_ hala (oO)
ae ;
oe Files Cnameble tlle _acinnlact_ oh aameL l= ‘Eig, Ad!
: print rsa” 0% Fret rencl| afl rama inne name)
____—
‘pale Or es ses
ff Gore ea
at
by Minclade catdio bd
tot main 0)
feat Hlootee, mater a, bye,
ie:
prot C pease ly dt Ta concord Kflomofer to mater”):
griolt (* Nn 2 Te. Conuort me\ar to Efl onde e\n7);
Seant C2" Rchoice)s
twiteh (choco)
4
Care At
pasty ce Eador any leaglh vq. Kilemeter.\n "
Seanp OP, Ree): :
be «¥ Lesd 5
peintt (leagih Va meters n€" by),
break +
Oa4 2. :
post (Fate any Langit Cn aderia es
seantlag’, BED, ;
| d= c/Aesd :
Pink Leagth fn mater klomofant 45", 45
Sorak' a f
x
de olf:
pendent J chores); J
Pathim of 2oO
ay Hf trelucto catdio-hy
fat panin ©)
{
| or (int a6; arel) a+t-) £
LgecGolesr be=45 beef
Sprite ed % bs |
(pec XZ)
ponte ("\9); 3
cafuen Qo}
4
|
by Hincdude cvtdo hs
tat main () ; ‘ ar
a
int nun, num ®, Sum, A vores ee
[prot C a tule: Molen ek ;
seang Che 4, n4" ‘Bru mbagm? ))
Sum= num + me
= gum | a ;
reagt The sum [a avon? qret he um la.
ras)
tank =
; wlq. By on olude catdio er
| eo ein ©)
| tat es RoSam)
| Sum edumt a
“petal O Thos 2 ol See;
atP,
4
hile (a¢=919)5
- Pafarn 95—2
by thineludde cule(Pody7
int mata C)
tal oh “
iprialy Labor any number);
feo aq Che Al &a) $s
4 (apa)
{ =
proaty a The number 1 positive \n”)>
, |
2}so if fae o)°
ns t ; es
eae numbsrny negative \n') je. 2
t “ - 2 a A if re
panty(" the number iy zero\a" yy,
4 ee
cetGen oF
5as) Hinclube edie h>
: ind main 0)
tat ac d|, be te0Gsum7
Ubitle (ae 4000)
aries
if Ca%ib== 0)
print ek vie.) :
4
ie sym $2
APPy os
he - ;
Fe ent:
atin of
an
Oo ate tage
The odd numbec gre -
+ 6-3 4ae
SECTION 424 Martel
1 Define each af the folluveiny as wee
amassed in CHF prog
ening
ay Clas
Wy Polsmonphise —e) Inertance — d) Comments
Write a simp
onram to demonstrate the structire of a C+ program, Let your
Aisplay Your Gall game, registration number and year of completion your diploma stuilies
Where each sem shimld he yn afferent fe [4 marks}
. Write the ouput of the fallowing source cod: marks}
include (ostream
using mamespra
int naing
Sloat num = 4456. num:
cout «This program compures "nun << "and" = num? “en
result ~ (rem nuana2)? rnd: mum?
cour" sumber is "result;
retwn 0,
)
4. Differentiate each of the following:
red:
i) global variable and local variable ji) array and string [marks]
5, Write a simple program that will calculate the following arithmetic operation and display &
follows:
sX3~40 [M marks}
6. Write the general syntax of each of the following: {4 marks}
a) Switch ease —b) do white oop ¢) function definition d) function declaration
Section B [36 Marks}
7.a) Write the C++ source code that will generate the following pattern: Jo marks}
123456
12345
p2a4
r23
12
1
b) Write a C++ program that prints 105 up t0 1245 in descending onder. Also fet your Pe
compute the sum of this series Use do while loop: \oms
Page 20f3Soh Wine
he joqpht subst Moon ther user Finally
scr ay
HUET HA WATE accep igen HEE
Your pn
Westam should dinplay thine
pvp tae ater! SAE [to marsh
ww, ae aan
eae
#> sonttee ean se quoticnt af any twos Moat
Coe that wih caeanate ewe peaivct menace OF Hy 1 foatmnp
Mumtbery Uspenaings an yn
hers ure rmmtezer Use swatelt
: 21 ationeeAsgune Hal HE
cane “
* Jeo marks!
aw,
aces
7 Preprnaiy cy with eautans [Senn an beng
Mem Your ime 1 that culculate the whanne af Me eyinuter wath eats ens an 1 Teeny
1 are main # Yared veylinder (1
whe veylindert )
fuse
EEMTE SHeud cunisayty pays fasts. sl
function has
Caen neon hay the values of the radi as awe ae Bengt and
lculate the vealame al the gy ‘
fo Compute the saliame
he
Me wy
Iinder aut hapayrthe result The velit tne the pew
OF the cyhimbe, Note tha» = Yeh sshete ¢ and Ware rndias and
Wf the cylinder allen em MW |x marks}
Uy Ansutise yu
Tt eu have Neen juven three amay of ch
Middle name ive well as last an
Wi "
ctets which are your first_name,
and those names Were itiahzed based on yout full name,
that will inplay ya
6 CHS prope
uals separated hy cntnttia® {4 marks}
8 ap Wane oO props
0 ay in 20+ propran that will extract numbers diviutde by 15 between St and 1000
eachiant The program should also caleutate the sum the series Use white loopy 16 marke)
by) What te the autput of fotlowiny source cade {6 marks]
includes vostream:
using namespace stf,
int main()
{
att &
lub
cout:
ony Ut
fue)
goto lab,
yrseerall,
cout Tako mons
_| a a : os "fran one dorm 7 ee
dofa dnd’ ita
ethor,
a g TnhertFance wl ee ckject ace iu tree all
| sho propertier ane) belaviou cr
EME nn ne rae
gy te pares obyeots_
ee
4d) Comment a Hniphy feat thal gaoredl
r iota f
a tho _tomettar, buf that may enfom
the lander ‘gj wheal you ane dei'g
_Fany particular petafin your
eee Partie + eas poa. Ithineluds zation y
| iat marn ()
char mamo LJ =ally John f
lat rag = Dolooteul? .
int yout = ROC a
pri OA! name) ° _ ea a
PeSCTAN AT rg)
paintt d\n", year), ee
Crdurn op
Soe Program tempqret 4 EB b and Plas
| ‘the greeter umber '¥ pe lA:
|Loe
I) gle v arable, Vaca ble | M thet aH gec\
ide a function or re
| ~~ \dhtle
__glebal sath are co doa! baad)
ss coulvic
ack Bate
—* ; C- eleps Sk Ee
—
2 the gees -
y ee —
hey, " + dy intive thet A
ements o feasting?
Mas pthessame alt Nye
| wleng wea whe charets
a
Hindulada'o a 5 : PTs 2
__int main c) —
[Naas 6} b: —— iS ae
| be3s —
ie ¢ ms at are yl tbe
Ke ep Ae
at W en eee
(kd YE
vatr wel", wae ee
1 OT Se teGi B® Sel care!
yada
Suitch CE xpranion \
e
v
Gar 4d _
black 4°
break :
Case O°
block 9
brow ks
Quo nt
Bock nn
broak. *
dlafatt :
Tatement |
& by do ultte loop -
aystox
eo
{
beady ay Me loop
4
While (cond t rey \yEnea Function deginitien ee
__Syntae
eaten type _fundion. feo Ate)
: dy Function dadacafion : -
Syntax - il
Wye ran Ties aam 2 (type Cargnamed C pet
a) Hincl ele astd'te “h >
re main vy ee
i
_lder (of a2 67 ay q--) £ De
Hee Craft b= th bese bet) .o -
priate ZP", b); ¥ _
point (07) 4 ______~
eapyrs OF ue ue
a
ae2 incl Ab ziidiovhs
(Ong
y inclu
fal” man ©)
_
4
| int a= 1945 Sum?
Lo
Sum dum +),
| ar;
pantt( The dum of Lever wih a", gum )5
§
tdhtle (a> = J08)}
votuin 058 yy HE include aot to-h>
Inf main 1) oa 7
tat al22 ize t, bi! f i ah
yea Enfer sj2o 3 = fh
SeangC “4A”, uno); on it
for (Leo; ce £205 CFP) eee
fatty,
big = atolls kee
fee (t=44 Le aMize% itt) £ wets
ifebigeated) | oS
big = ated; ee ee
oo
nd bie J
oo \n the biggest abe mentee Zech
Peta (Oo eeeSi by Rigg tale voehy
lal main oO)
£
|
| tat qum4 num a;
lint chetce
pages 4 To calewlote product 4 furs nunber
":
pooh \ 8 To caleel ofa tte seta a Tule num
j bee \a ny _ s ci :
Meanp OAT Reefer) i pal
[printf Enter np two numbeclf);
Kean Oe%d, ud", 7 Bae Banwen9)
| susiteh Cehoice) {
lease a a iad
[iota “ge
[qe num’ ® num aa
senteZ\a ee)
break »
ise eee
brat
b =Numd Jaume a
Pointe eda", 6).
~~ | break + fe ||
8 poet nArwQ- -— 5 _
depatt | Se
met \ Tremor Taveli rd chovee " ica" Vp
|
| et
—f
| ——
le
= rlay Bincluclocvidie- h>
| fleet veylineler int wth)
We Se,
fat enaia ()-2 |
Lt = 15, Ahaignf = tot '
ce
Volume =z Y% veolar ee pus, ur, baigh);
peintt (8 Nelume 4 et 4\ 0%, Velume)S
calim ©; SS
“fost aa orCint inthe
[ie = ££“| pated \at 00) 1
Jd sy HinducQe cutie h>
int mein 0) i
tol weal, be too sums
While Cae 4200)
{
| ig tevin == 0)
priest (Dna). i ole :
ba en
Sum esq $E3
at?
a
1
ratym oF
4.
a oe > A
307 6 5 48
The odd number aie.