Monday, August 11, 2014

QBASIC PROGRAMMING (2014)



1.WAP to input any number and check whether the given no. is divisible by 5 or not.

   REM
    CLS
    INPUT “Enter any number:”; N
    IF N MOD 5 = 0 THEN
    PRINT “The given number is divisible by 5”
    ELSE
    PRINT “The given number is not divisible by 5”
    END IF
    END





2.WAP to input any number and check whether the given no. is divisible by 3 and 7 or not.


    REM
    CLS
    INPUT “Enter any number ”; N
    IF N MOD 3 = 0 AND N MOD 7 = 0 THEN
    PRINT “The given number is divisible by 3 and seven”
    ELSE
    PRINT “The given number is not divisible by 3 and 7”
    END IF
    END


3.WAP to input any number and check whether the given no. is positive, negative or zero.


    REM
    CLS
    INPUT “Enter any number:” ; N
    IF N > 0 THEN
    PRINT “The given number is positive”
    ELSE IF N < 0 THEN
    PRINT “The given number is negative”
    ELSE
    PRINT “The given number is zero”
    END IF
    END


4.WAP to input any number and display whether it is odd or even.


    REM
    CLS
    INPUT “Enter any number :” ; N
    IF N MOD 2 = 0 THEN
    PRINT “The given number is even”
    ELSE
    PRINT “The given number is odd”
    END IF
    END



5. Input a mark in a subject of a student and check if the student is pass or nor. [Pass Mark >=40]


    REM
    CLS
    INPUT "Enter your marks :"; M
    IF M >=40 THEN
    PRINT "You are passed"
    ELSE
    PRINT "You are failed"
    END IF
    END



6.     WAP to enter any two numbers and display the greater one.


    REM
    CLS
    INPUT “Enter any two numbers:”; A,B
    IF A>B THEN
    PRINT A; “is greater”
    ELSE
    PRINT B; “is greater”
    END IF
    END


7.     WAP to enter any three numbers and display the greatest one.


    REM
    CLS
    INPUT “Enter any three numbers:”; A,B,C
    IF A>B AND A>C THEN
    PRINT A; “is greatest”
    ELSE IF B>A AND B>C THEN
    PRINT B; “is greatest”
    ELSE
    PRINT C; “is greatest”
    END IF
    END


8.     WAP to display all natural nos from 1 to 100. [USE FOR…NEXT, WHILE….WEND, DO WHILE……LOOP, DO….LOOP WHILE, DO UNTIL….LOOP, DO….LOOP UNTIL]


i. FOR…. NEXT


    REM
    CLS
    FOR I = 1 TO 100
    PRINT A,
    NEXT A
    END


ii. WHILE……WEND


    REM
    CLS
    I = 10
    WHILE I<=100
    PRINT I,
    I= I + 10
    WEND
    END


iii.DO WHILE ….LOOP


    REM
    CLS
    I = 10
    DO WHILE I <= 100
    PRINT I,
    I = I + 10
    LOOP
END

iv. DO….LOOP WHILE


    REM
    CLS
    I = 10
    DO
    PRINT I,
    I = I + 10
    LOOP WHILE I <= 100
    END

v. DO UNTIL….LOOP


    REM
    CLS
    I = 1
    DO UNTIL I > 100
    PRINT I,
    I = I + 1
    LOOP
    END


vi. DO….LOOP UNTIL


    REM
    CLS
    I = 1
    DO
    PRINT I,
    I = I + 1
    LOOP UNTIL I>100
    END


9.     WAP to display 10,20,30….100. . [USE FOR…NEXT, WHILE….WEND, DO WHILE……LOOP, DO….LOOP WHILE, DO UNTIL….LOOP, DO….LOOP UNTIL]


i. FOR….NEXT


    REM
    CLS
    FOR I = 10 TO 100 STEP 10
    PRINT I,
    NEXT I
    END


ii. WHILE…WEND


    REM
    CLS
    I = 1
    WHILE I <=100
    PRINT I,
    I = I + 1
    NEXT I
    WEND
    END


iii. DO WHILE….LOOP


    REM
    CLS
    I = 1
    DO WHILE I <= 100
    PRINT I,
    I = I + 1
    LOOP
    END


iv. DO….LOOP WHILE


    REM
    CLS
    I = 1
    DO
    PRINT I,
    I = I + 1
    LOOP WHILE I <= 100
    END


v. DO UNTIL…..LOOP


    REM
    CLS
    I = 10
    DO UNTIL I > 100
    PRINT I,
    I = I + 10
    LOOP
    END


vi. DO….LOOP UNTIL


    REM
    CLS
    I = 10
    DO
    PRINT I,
    I = I + 10
    LOOP UNTIL I > 100
    END


10. WAP to display all even numbers from 50 to 1. [USE FOR…NEXT, WHILE….WEND, DO WHILE……LOOP, DO….LOOP WHILE, DO UNTIL….LOOP, DO….LOOP UNTIL]


i. FOR….NEXT


    REM
    CLS
    FOR I = 50 TO 2 STEP -2
    PRINT I,
    NEXT I
    END


ii. WHILE…..WEND


    REM
    CLS
    I = 50
    WHILE I <= 2
    PRINT I,
    I = I – 2
    NEXT I
    WEND
    END


iii. DO WHILE……LOOP


    REM
    CLS
    I = 50
    DO WHILE I <= 2
    PRINT I,
    I = I – 2
    LOOP
    END


iv. DO LOOP…..WHILE


    REM
    CLS
    I = 50
    DO
    PRINT I,
    I = I – 2
    LOOP WHILE I <= 2
    END


v. DO UNTIL….LOOP


    REM
    CLS
    I = 50
    DO UNTIL I<2
    PRINT I,
    I = I – 2
    LOOP    END


vi. DO….LOOP UNTIL


    REM
    CLS
    I = 50
    DO
    PRINT I,
    I = I – 2
LOOP UNTIL I<2
END