Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Section A Section #
*n +er ALL ,ue tion in t%i ection*n +er to ,ue tion are to (e gi.en on t%e e ,ue tion paper /or ,ue tion ! to 01 circle t%e correct an +er - 2! mar3 eac%4
$otal %ark !- In t%e " programming language1 program e5ecution tart at +%ic% function6 c4 8 tem d4 rand2 4 a4 7ain 2 4 (4 main 2 4 29#*USE:4 &- T%e e5pre ion 5 ;<5= mean i- 5 < 5 ; i.- 5 ii- 5;;= iii- ;;5= != <5;5= a4 i1 ii and iii c4 ii and iii onl8(4 i. onl8d4 *ll t%e a(o.ec4 a a preproce ?define or directi.e +it%
&
>- "on tant are defined a4 at t%e end of a (4 at t%e (eginning of a functionfunction d4 at t%e part of t%e program +%ere t%e8 are u ed '-
x and y are integer .aria(le - T%e di.i ion x/y gi.e a +rong an +er- @%ic% of t%e follo+ing +ould rectif8 t%e pro(lem6 b) float x / float c) (float) x / y d) (float x) / y a) y / x y
0- @%at i t%e cau e of t%e error : num2 undeclared a4 num& i not declared at t%e end of t%e c4 function num& i not initialiAed +it% a .alue (4 num& i not declared at t%e (eginning of t%e d4 function num& %ould (e declared a num?&
6.
#ut a tic3 2 4 for .alid identifier and a cro 2 4 for in.alid identifier - /or in.alid identifier 1 gi.e a rea on or rea on for t%eir in.alidit8- 20 mar3 4 Identifier _it(Cedu 3e8Num(er *cce "ode Balid 2 4 or In.alid 2 4 Rea on2 4 if in.alid
7.
"on.ert t%e follo+ing mat%ematical e5pre ion into " language e5pre ion - * ume all .aria(le are floating point - 2U e !" for 8m(ol and li(rar8 function co 24 for co ine4 2& mar3 eac%4
a-
T =
1 2
mgh y 2
(-
c-
E- @rite a scanf() tatement to accept 3e8(oard entr8 into eac% of t%e follo+ing .aria(le indicated2! mar3 eac%4 a) c%aracter .aria(le option
a) Results: Blackburn 4 Arsenal 3 +%ere t%e .alue ' and > are tored in .aria(le bla and ars re pecti.el8
b) The area of the circle# 3 is 3.03 meter s uare +%ere t%e .alue > and >-)> are tored in .aria(le no and area re pecti.el8
!)- "ircle all t%e error in t%e program (elo+ and re(rite t%e corrected program- 2!& mar3 4
#inclu!e "st!io.h# !efine $% 3.4&' main() int r) float Area) print (*$rogram to calculate the area of a semicircle+)) printf (*,nter ra!ius r: *)) scanf (*-!*. /r) Area 0 &1' 2 $% 2 r 2 r) printf (*The area is -.'f*. /Area)) 3 14,n! of main function14
&D'
!!- @%at +ill t%e follo+ing print6 2& mar3 4 float a < !-G'!H1 ( < G)-0&>= int c<!&= printf29*fi, i Id 8ear oldJnJJand %e i I-&f meter tall and +eig% a(out I-!f 3g-JJJJ:1 c1 a1 (4=
2! mar3 eac%4
c)
e)
>D'
13. *
ume .aria(le X i an integer1 find t%e .alue of X: 2! mar3 eac%4 a) X < H D 0 N !! b) X < 2!E ; G4 D &0 c) N X> < F ; ! N !)-0 < < <
14. Suppose x=5, y=3 and z=1. Write down the output for the following statements. Write nothing if nothing is printed. (1 marks each) a)
b)
! !
c)
! !
!0-
Stud8 t%e egment of program (elo+ and an +er t%e ,ue tion t%at follo+s'it(h ((hoi(e) { (ase )* printf(+,n-. /amilton brea0
+)
2> mar3 4
2& mar34
2d4 Re+rite t%e a(o.e egment u ing t%e ifelse if..else control tructure
2E mar3 4
0D'
INSTITUT TEKNOLOGI BRUNEI Department of Electrical and "ommunication Engineering "omputer #rogramming $ #%a e Te t !
Section # ()0 marks) 50 mins *n +er Oue tion ! in t%i ection- Su(mit t%e flopp8 di 3 containing t%e program 1. @rite a program t%at prompt t%e u er for t%e .alue of t%e lengt%1 l1 and %eig%t1 h1 of a rig%t angled triangle 2 ee /ig OB!4 and t%en compute t%e %8potenu e c1 t%e area of t%e triangle and t%e angle x in degree c x l /ig OB! T%e formulae for t%e re,uired ,uantitie are a follo+ h *ll mea urement in cm
c = l 2 + h2 1
h x = tan 1 l
Gi.e all 8our an +er accurate to t+o decimal place and 5 to (e pre ented in degree * po i(le printout of 8our program ma8 (e a %o+n in t%e creen %ot (elo+-
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: This pro;ram (al(ulates the hypotenuse, the area and one of the an;les of a ri;ht an;le trian;le. The user has to enter the len;th and hei;ht of the trian;le ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: <nter the len;th l * = <nter the hei;ht h * #6 8esults ======= /ypotenuse = #&.># (m 5rea = &>.& (m?3 5n;le x = &&.6) de;ree T%e e .alue 1 F and !> are entered (8 t%e u er-
Ot%er te t .alue : a- l< !&1 %<!0 (- l<'1 %<F re c- l<>>1 %<&0 d- l<!01 %<!0
re ult : R8potenu e < !0-G& cm1 *rea<G)-) cm&1 *ngle 5 <0)-!FO ult : R8potenu e < F-E0 cm1 *rea<!E-) cm&1 *ngle 5 <GG-)'O re ult : R8potenu e < '!-') cm1 *rea<'!&-0 cm&1 *ngle 5 <>H-!0O re ult : R8potenu e < &!-&! cm1 *rea<!!&-0 cm&1 *ngle 5 <'0-))O
"#&)!!D#T!
!D!