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


Top Related