midterm exam in qbasic

2
Name: Sec: Group A 1. What will be displayed when the following programs are executed? a. FOR i = 2 TO 10 FOR j = 2 TO i - 1 IF i / j = FIX(i / j) THEN 1 NEXT j PRINT i; 1 NEXT i END Ans.: b. DIM a(3) READ n FOR i = 1 TO 3 a(i) = n MOD 10 n = INT(n / 10) NEXT i FOR i = 0 TO 2 FOR j = 0 TO 2 IF i = j THEN 1 FOR k = 0 TO 2 IF k = i OR k = j THEN 2 PRINT a(1) * 10 ^ i +a(2) * 10 ^ j + a(3) * 10 ^ k; 2 NEXT k 1 NEXT j NEXT i DATA 123 END Ans.: c. READ x DO WHILE x < 5 IF x = 4 THEN RESTORE END IF z = x + y READ x, y LOOP PRINT z DATA 3, 4, 6, 8, 1, 2, 5, 9, 3 END Ans.: d. FOR i = 1 TO 9 STEP 2 s = 0 FOR j = 1 TO i STEP 2 s = s + j NEXT j PRINT s; NEXT i END Ans.: Menoufiya University Faculty of Engineering Shebin El-Kom Midterm Exam 3 rd Mechanical Power Engineering Department: Mechanical power Engineering Subject: Computer Applications Time Allowed: 45 min

Upload: dr-samy-el-behery

Post on 21-Dec-2015

3 views

Category:

Documents


0 download

DESCRIPTION

Midterm exam in Qbasic

TRANSCRIPT

Page 1: Midterm exam in Qbasic

Name: Sec: Group A1. What will be displayed when the following

programs are executed?a. FOR i = 2 TO 10

FOR j = 2 TO i - 1IF i / j = FIX(i / j) THEN 1NEXT jPRINT i;1 NEXT iEND

Ans.:b. DIM a(3)

READ nFOR i = 1 TO 3a(i) = n MOD 10n = INT(n / 10)NEXT iFOR i = 0 TO 2FOR j = 0 TO 2IF i = j THEN 1FOR k = 0 TO 2IF k = i OR k = j THEN 2PRINT a(1) * 10 ^ i +a(2) * 10 ^ j + a(3) * 10 ^ k;2 NEXT k1 NEXT jNEXT iDATA 123END

Ans.:c. READ x

DO WHILE x < 5IF x = 4 THENRESTOREEND IFz = x + yREAD x, yLOOPPRINT zDATA 3, 4, 6, 8, 1, 2, 5, 9, 3END

Ans.:d. FOR i = 1 TO 9 STEP 2

s = 0FOR j = 1 TO i STEP 2s = s + jNEXT jPRINT s;NEXT iEND

Ans.:

Menoufiya UniversityFaculty of EngineeringShebin El-KomMidterm Exam

3rd Mechanical Power EngineeringDepartment: Mechanical power EngineeringSubject: Computer ApplicationsTime Allowed: 45 min

Page 2: Midterm exam in Qbasic

e. a$ = "1546"b$ = "4"MID$(a$, 2, 1) = b$a$ = STR$(5) + a$a = VAL(a$) + LEN(a$)PRINT a

Ans.:

2. Suppose you have the flowing set of numbers(5, 112, 20, -3, 70, 40, 15, 50, 111, 80, 22, 13)Write a computer program the counts the odd and even numbers then the program sorts the odd number in ascending order and the even number in descending order. The output should be the original number set and the odd and even number in the required order