Vous êtes sur la page 1sur 5

INSTITUT TEKNOLOGI BRUNEI Name: Department of Electrical and Communication Group: Engineering Time allo&ed : " %r '( Computer

#rogramming $ #%a!e Te!t " minute! Section A (60 marks) 40 mins +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 "(0 circle t%e correct an!&er!- 1" mar2 eac%3 "- 4ig% le.el language in!truction! are a3 in )inar5 code! )3 Engli!%6li2e c3 in mnemonic!

Seme!ter " ""t% Septem)er '((* Section A Section B Total Mark

d3 mac%ine code!

'- C comment! are delimited )5 )3 79888 c3 :n888:n d3 ; 8888-< a3 78887 97 =- +n algorit%m i! a3 a mat%ematical function )3 a !erie! of logical !tep! &%ic% !%o& %o& a ta!2 i! to )e done c3 a !erie! of !tep! to de)ug a program d3 none of t%e a)o.e >- ?%ic% of t%e follo&ing !tatement1!3 increa!e1!3 t%e .aria)le @ )5 "(A i- @ B @ C i.- @ ii- @CCD iii- CC@D "(D CB"(D a3 i0 ii and iii c3 i and i. onl5)3 i. onl5d3 +ll t%e a)o.e-

E- ?%ic% of t%e follo&ing !tatement1!3 i!7are trueA i- #rogram e@ecution !tart! at t%e main13 ii- function C i! ca!e !en!iti.e iii- Comment! are ignored )5 t%e compiler! i.- Content in a .aria)le cannot )e c%anged a3 i0 iii and i. c3 ii0 iii and i. )3 i0 ii and iii d3 all of t%e a)o.e

F- Garia)le! are declared a3 at t%e end of a function)3 at t%e )eginning of a functionc3 at t%e part of t%e program &%ere t%e5 are u!edd3 at t%e cu!tomH- T%e float 2e5&ord i! a3 u!ed to de!cri)e a .er5 lig%t .aria)le)3 u!ed to declare .aria)le! t%at %old c%aracter!c3 u!ed to declare .aria)le! t%at %old integer!d3 u!ed to declare .aria)le! t%at %old floating point num)er!*- Integer x i! di.ided )5 integer y a! follo&!: x/y D T%e fractional part of t%e re!ult of t%i! di.i!ion i! incorrect- ?%ic% of t%e follo&ing &ould rectif5 t%e pro)lemA c) (float) y / d) (int) x / y a) y / x b) (float) x / y (float) x I- ?%ic% of t%e follo&ing !tatement declare! an integer .aria)le a3 int c%oice B J'K )3 c%ar c%oice B '(( c3 int option B '((( d3 /loat c%oice B '(
C#'((*7#T"

"7E

"(- T%e follo&ing !tatement: printf 1LT%e area of t%e rectangle i! M-'f<0 area3D gi.e! t%e error of ;undefined !5m)ol area< T%e error i! due to a3 mi!!ing !emicolonc3 unterminated !tring )3 mi!!ing .aria)le d3 Garia)le area i! not declared

666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 666666666666666666666666666666666666666666666666666666666666666 11. #ut a tic2 1 3 for .alid identifier! and a cro!! 1 3 for in.alid identifier!- /or in.alid identifier!0 gi.e a rea!on or rea!on! for t%eir in.alidit5- 1"( mar2!3 Identifier! RoomNo-H Ne!OrNo Roti K%a&in 'Coo2 H fi!% int Galid 1 3 or In.alid 1 3 Rea!on1!3 if in.alid

"'- Con.ert t%e follo&ing mat%ematical e@pre!!ion! into C language e@pre!!ion!- +!!ume all .aria)le! are floating point!- 1U!e !" for !5m)ol 3 1' mar2! eac%3

a-

T =

1 2

mgh y 2

)-

F =G

m1 m2 d2
1 2 at 2

cd-

s = ut +

x = 2 sin 5t 4 cos 5t

1U!e li)rar5 function cos() and sin() for co!ine and !ine re!pecti.el53

"=- ?rite a scanf() !tatement to accept 2e5)oard entr5 into eac% of t%e follo&ing .aria)le indicated1" mar2 eac%3 a3 integer .aria)le co#nt

)3 floating point .aria)le $erimeter

">- ?rite $rintf() !tatement! to print t%e follo&ing me!!age!- 1" mar2 eac% 3 a3 4er office i! on t%e F(t% floor &%ere t%e .alue F( i! !tored in .aria)le le%el

C#'((*7#T"

'7E

)3 T%e area of t%e circle i! =-(= meter !,uare &%ere t%e .alue =-(= i! !tored in .aria)le area

"E- Circle all t%e error! in t%e program )elo& and re&rite t%e corrected program- 1"( mar2! 3 #include <stdio.h> #include <conio.h> main() clrscr(); int base, height; float area; print ("Program to calculate area of a triangle \n",area); printf ("Enter the base "); scanf ("!d","base) printf ("Enter the height ", "height); scanf ("!d", height); area # $ % & ' base ' height;

printf ("(he area of the triangle is !f", "area); ) %'End of main function%'

C#'((*7#T"

=7E

"F- ?%at &ill eac% one of t%e follo&ing printA 1' mar2! 3 float a B "-F>"H0 ) B F(-E'=D int cB"'D printf1;+fi, i! Md 5ear! old:nand %e i! M-'f meter tall :nand &eig%! a)out M-"f 2g-;0 c0 a0 )3D

"H- /or eac% of t%e follo&ing0 &rite a !ingle !tatement t%at declare! and a!!ign! initial .alue t%e .aria)le indicated1" mar2 eac%3 a3 Garia)le re$ly to %a.e an initial .alue of '()

)3 Garia)le co#nt to %a.e an initial .alue of *0

c3 Garia)le area to %a.e an initial .alue of +00,++

"*- +!!ume @B"( and 5BH &%ere )ot% @ and 5 are integer .aria)le!0 &%at &ill )e t%e !creen output for t%e follo&ing !tatement!A 1If not%ing i! di!pla5ed0 t%en an!&er ;not%ing<3 1" mar2 eac%3 printf 1;Md<0 53D printf 1;Md<0 @C53D printf 1;@B<3D printf 1;@BMd<0 @3D printf 1;Md and Md<0 50 @753D O B @ $ 5D 79printf 1;@C@C5 B Md<0 @C@C53D97 printf 1;:n<3D !canf 1;Md<0 P@3D printf 1;t%i! i! Md<0 57@3D

"I- +!!ume .aria)le Q i! an integer0 find t%e .alue of Q: 1" mar2 eac%3 a3 )3 c3 Q B * 7 E 9 "" Q B 1"* C F3 7 =' 9 Q= B I-E C " 9 "(-E B B B >7E

C#'((*7#T"

INSTITUT TEKNOLOGI BRUNEI Department of Electrical and Communication Engineering Computer #rogramming $ #%a!e Te!t "

Name: Group: Seme!ter " ""t% Septem)er '((*

Time allo&ed : " %r '( min!

Section B (40 marks) 40 mins +n!&er ALL ,ue!tion! in t%i! !ection- Su)mit t%e flopp5 di!2 containing t%e program!"a- ?rite a function0 called My-ar(). t%at print! t%e picture a! !%o&n )elo&

)- Ra2ing u!e of t%e My-ar() function to print out t%e car0 &rite a program to di!pla5 t%e !creen )elo&- Name t%i! program !T*/*,c

'- ?rite a program to calculate t%e re!onant fre,uenc5 of a !erie! RLC circuit- T%i! program &ill prompt t%e u!er for t%e .alue! of t%e capacitor0 C and t%e inductor0 L- T%e formula to find t%e re!onant fre,uenc5 i! !%o&n )elo&:

Resonant Frequency , f =

1 2 LC

Define a! a con!tant &it% a .alue of 0,*4+ in 5our program- T%e calculated .alue of re!onant fre,uenc5 i! to %a.e accurac5 up to t&o decimal place!+ po!!i)le printout of 5our program ma5 )e a! !%o&n in t%e !creen!%ot )elo&-

T%e!e .alue! are entered )5 t%e u!er-

Name t%i! program a! !T*/+,c

C#'((*7#T"

"7"

Vous aimerez peut-être aussi