Saturday, September 23, 2017

Selection Structure – Find Output [SEE QBASIC PRACTICE]

Write the output of the following programs: [10 Programs]



1.     DECLARE SUB TEST(NUM)
CLS
CALL TEST(-5)
CALL TEST(5)
CALL TEST(0)
END

SUB TEST(NUM)
SELECT CASE NUM
CASE IS < 0
M$ = “Negative”
CASE IS > 0
M$ = “Positive”
CASE ELSE
M$ = “Zero”
END SELECT
PRINT NUM; ”is”; M$
END SUB

2.     DECLARE SUB SERIES ( )
CLS
CALL SERIES
END

SUB SERIES ( )
A = 1
B = 1
PRINT A; B;
X:
LET C = A + B
PRINT C
LET A = B
LET B = C
IF C <= 8 THEN GOTO X
END

3.     DECLARE SUB MIN(A, B)
CLS
A = 5
B = 10
CALL MIN(A, B)
END

SUB MIN(A, B)
IF A < B THEN
C = A + 5
PRINT C
ELSE
PRINT B ^ 2
END IF
END SUB

4.     DECLARE SUB OUTP(A$)
CLS
A$ = “COMPUTER”
CALL OUTP(A$)
END

SUB OUTP(A$)
B = LEN(A$)
C = 1
LAB:
PRINT LEFT$(A$, C)
C = C + 1
IF C <= B THEN GOTO LAB
END SUB

5.     DECLARE SUB OUTPOOT(L, B)
CLS
LET L = 15
LET B = 10
CALL OUTPOOT(L, B)
CALL OUTPOOT(3, 6)
END

SUB OUTPOOT(L, B)
IF L < B THEN
PRINT L
ELSE
PRINT
PRINT B
END IF
END SUB

6.     DECLARE SUB FEBON(P, Q)
CLS
R = 2 : S = 1
CALL FEBON(R, S)
END

SUB FEBON(P, Q)
T = 1
PRINT P; Q;
LAB:
LET U = P + Q
PRINT U;
P = Q
Q = U
T = T + 1
IF T <=8 THEN GOTO LAB
END SUB

7.     DECLARE SUB OTP( )
CLS
CALL OTP
END

SUB OTP ( )
CLS
A = 4
B = 5
C = A ^ 3 - B ^ 2
D = C - A + B
E = C \ D
F = C MOD D
IF E > F THEN
PRINT "HOW LOGICAL"
ELSE
PRINT "NO LOGIC AT ALL"
END IF
END
END SUB

8.     DECLARE FUNCTION OUT(A, B)
CLS
D = OUT(17, 7)
PRINT D
END

FUNCTION OUT(A, B)
R = A MOD B
IF R MOD 2 = 0 THEN
C = R MOD 6 + 30
ELSE
C = R MOD 6 + 15
END IF
D = C \ 5
OUT = D
END FUNCTION

9.     DECLARE FUNCTION ABC(A, B, C)
CLS
X = 10
Y = 20
Z = 30
G = ABC(X, Y, Z)
PRINT G
END
FUNCTION ABC(A, B, C)
IF A>B AND A<C OR A<B AND A>C THEN
GG = A
ELSEIF B>A AND B<C OR B<A AND B>C THEN
GG = B
ELSE
GG = C
END IF
ABC = GG
END FUNCTION

10.  DECLARE FUNCTION amt(q, r)
CLS
READ q, r
DATA 5000, 10
PRINT “Amount=”; amt(q, r)
END

FUNCTION amt(q, r)
IF (q > 1000) THEN dis = 10
total = (q* r) – (q* r *dis / 100)
amt = total
END FUNCTION


***

5 comments:

  1. declare sub result(0
    cls
    call result
    end
    sub result()
    for i = 1 to 6
    read n
    s$ = s$ + chr$(n)
    next i
    print s$
    data 83, 101, 108, 102, 105, 101
    end sub
    what wii be the output of the following program?
    i found this question in reputed school practice set? i found there is error? plz help

    ReplyDelete
  2. declare function count (a$) a$ = "databackup" PRINT count(a$) END FUNCTION count (a$) FOR x = 1 TO LEN(a$) m$ = "mid$(a$,x,1)" IF m$ = "a" THEN c = c + 1 END IF NEXT x count = c END FUNCTION
    output please?

    ReplyDelete
  3. DECLARE SUB Series()

    CALL Series()

    END



    SUB Series()

    M=2

    N=1

    FOR K = 1 to 5

    PRINT N;

    M=M+1

    N = N * 10 +M

    NEXT K

    END SUB

    ReplyDelete