Qbasic programming
1) Wap to input any number and check whether the given number is divisible by 5 or not.
1) Wap to input any number and check whether the given number 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 number 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 7”
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 number is positive negative or zero.
REM
CLS
INPUT”Enter any number”; N
IF N>O
THEN
PRINT”The
given number is positive”
ELSEIF
N<0 THEN
PRINT”The
given number is negative”
ELSE
PRINT”The
given number is zero”
ENDIF
END
4) Wap to input any number and check whether
the given number 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”
ENDIF
END
5) Input a mark in a subject of student and check if student is
pass or not.
REM
CLS
INPUT ”Enter mark of a student”;S
IF S>=40 THEN
PRINT”The student is pass”
ELSE
PRINT”The student is fail”
END IF
END
6) Wap to input any 2 number and display the
greater one.
REM
CLS
INPUT”Enter first number”;A
INPUT”Enter second number”;B
IF
A>B THEN
PRINT
A;”is greater”
ELSE
PRINT
B;”is greater”
END
IF
END
7) Wap to input any 3 number and display the
greatest one.
REM
CLS
INPUT”Enter first number”;A
INPUT”Enter second number”;B
INPUT”Enter third number”;C
IF
A>B AND A>C THEN
PRINT
A;”is greatest”
ELSEIF
B>A AND B>C THEN
PRINT
B;”is greatest”
ELSE
PRINT
C;”is greatest”
END IF
END
8) Wap to display all natural numbers
from 1 to 100.
DO WHILE….LOOP
DO….LOOP
WHILE
REM
REM
CLS
CLS
I = 1
I= 1
DO WHILE I < = 100
DO
PRINT I,
PRINT I,
I = I+1
I = I +1
LOOP
LOOP WHILE I < =100
END
END
DO UNTIL….LOOP
DO….LOOP UNTIL
REM
REM
CLS
CLS
I = 1
DO UNTIL 1 > 100
DO
PRINT I,
PRINT I,
I = I+1
I= I+1
LOOP
LOOP UNTIL I
>100
END
END
FOR….NEXT
WHILE….WEND
REM
REM
CLS
CLS
FOR A = 1 TO 100
I = 1
PRINT A, WHILE I < =100
NEXT A PRINT I,
END
I = I +1
WEND
END
9) Wap to display 10, 20, 30….100.
DO WHILE….LOOP
DO….LOOP WHILE
REM
REM
CLS
CLS
I = 10
I
= 10
DO WHILE I < =
100
DO
PRINT
I,
PRINT I,
I = I+10
I =
I +10
LOOP
LOOP WHILE I < =100
END
END
DO UNTIL….LOOP
DO….LOOP UNTIL
REM
REM
CLS
CLS
I = 10
I = 10
DO UNTIL 1 > 100
DO
PRINT I,
PRINT I,
I = I+10
I= I+10
LOOP
LOOP UNTIL I >100
END
END
FOR….NEXT
WHILE….WEND
REM
REM
CLS
CLS
FOR A = 10 TO 100 STEP
1O I = 10
PRINT A,
WHILE I < =100
NEXT A PRINT I,
END
I
= I +10
WEND
END
10) Wap to display
all even numbers from 50 to 1
DO WHILE….LOOP
DO….LOOP WHILE
REM REM
CLS CLS
I = 50 I = 50
DO WHILE I < = 50 DO
PRINT I, PRINT I,
I = I - 2 I = I - 2
LOOP LOOP WHILE I < =1
END END
DO UNTIL….LOOP
DO….LOOP UNTIL
REM REM
CLS CLS
I = 50 I = 50
DO UNTIL I < 1 DO
PRINT I, PRINT I,
I = I - 2 I= I - 2
LOOP LOOP UNTIL I <1
END END
FOR….NEXT
WHILE….WEND
REM
REM
CLS
CLS
FOR A= 50 To 1 step-2
I = 50
PRINT A,
WHILE I <=1
NEXT A PRINT I,
END
I = I - 2
WEND
END
No comments:
Post a Comment