0% found this document useful (0 votes)
13 views8 pages

Q-Basic Practical

The document contains a series of Q-BASIC programming exercises aimed at BCA first-year students, each with a specific problem statement and corresponding solution code. The exercises cover various programming concepts such as loops, conditionals, string manipulation, and mathematical operations. Each program is designed to reinforce fundamental programming skills and problem-solving techniques.

Uploaded by

sharplearn0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

Q-Basic Practical

The document contains a series of Q-BASIC programming exercises aimed at BCA first-year students, each with a specific problem statement and corresponding solution code. The exercises cover various programming concepts such as loops, conditionals, string manipulation, and mathematical operations. Each program is designed to reinforce fundamental programming skills and problem-solving techniques.

Uploaded by

sharplearn0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Q-BASIC PRACTICAL PROGRAM QUESTIONS AND SOLUTIONS | BCA 1st YEAR P.

PATEL

Q.1) WAP TO CHECK WHETHER THE ASK NUMBER IS PERFECT SQUARE NUMBER OR NOT.
 CLS
 INPUT "ENTER ANY NUMBER"; N
 S = SQR(N)
 IF S = INT(S) THEN
 PRINT "PERFECT SQUARE"
 ELSE
 PRINT "NOT PERFECT SQUARE"
 END IF
 END

Q.2) WAP to print all odd numbers from 1 to 100 also print its sum.
 CLS
 FOR I = 1 TO 100 STEP 2
 PRINT I,
 S=S+I
 NEXT I
 PRINT “SUM OF ALL ODD NUMBERS FROM 1 TO 100=”; S
 END

Q.3) WAP to enter any three strings and print the longest one.
 CLS
 INPUT "ENTER FIRST STRING"; A$
 INPUT "ENTER SECOND STRING"; B$
 INPUT "ENTER THIRD STRING"; C$
 IF LEN(A$) > LEN(B$) AND LEN(A$) > LEN(C$) THEN
 G$ = A$
 IF LEN(B$) > LEN(A$) AND LEN(B$) > LEN(C$) THEN
 G$ = B$
 ELSE
 G$ = C$
 END IF
 PRINT "LONGEST STRING="; G$
 END

Q.4) WAP to print all even numbers from 2 to 100


 CLS
 FOR I = 2 TO 100 STEP 2
 PRINT I,
 NEXT I
 END
Q.5) WAP to ask any string and count total no. of vowels, consonants words and sentences.
 CLS
 INPUT "ENTER ANY STRING"; S$
 VC = 0
 CC = 0
 WC = 1
 SC = 0
 FOR I = 1 TO LEN(S$)
 B$ = MID$(S$, I, 1)
 C$ = UCASE$(B$)
 IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ = "O" OR C$ = "U" THEN
 VC = VC + 1
 ELSEIF B$ = " " THEN
 WC = WC + 1
 ELSEIF B$ = "." THEN
 SC = SC + 1
 ELSE
 CC = CC + 1
 END IF
 NEXT I
 PRINT "TOTAL NO. OF VOWELS= "; VC
 PRINT "TOTAL NO. OF CONSONANTS="; CC
 PRINT "TOTAL NO. OF WORDS="; WC
 PRINT "TOTAL NO. OF SENTENCES="; SC
 END

Q.6) WAP to print sum of cube of any three ask numbers.

 REM PROGRAM TO DISPLAY SUM OF CUBE OF ANY THREE INPUT NUMBERS


 CLS
 INPUT “ENTER FIRST NUMBER”; A
 INPUT “ENTER SECOND NUMBER”; B
 INPUT “ENTER THIRD NUMBER”; C
 S=A^3+B^3+C^3
 PRINT “SUM OF CUBE OF THREE NUMBERS ”; S
 END

Q.7) WAP to enter any 10 numbers and sort in ascending order.

 CLS
 DIM N(10)
 FOR I = 1 TO 10
 INPUT "ENTER THE NUMBERS"; N(I)
 NEXT I
 FOR I = 1 TO 10
 FOR J = 1 TO 10 - I
 IF N(J) > N(J + 1) THEN SWAP N(J), N(J + 1)
 NEXT J
 NEXT I
 PRINT "NUMBERS ARRANGED IN ASCENDING ORDER"
 FOR I = 1 TO 10
 PRINT N(I)
 NEXT I
 END
Q.8) WAP to ask number and check whether the given number is composite or not.
 CLS
 INPUT "ENTER ANY NUMBER"; N
 C=0
 FOR I = 1 TO N
 IF N MOD I = 0 THEN C = C + 1
 NEXT I
 IF C <> 2 THEN
 PRINT N; "IS COMPOSITE NUMBER"
 ELSE
 PRINT N; "IS NOT COMPOSITE NUMBER"
 END IF
 END

Q.9) WAP to enter any three strings and print the shortest one.
 CLS
 INPUT "ENTER FIRST STRING"; A$
 INPUT "ENTER SECOND STRING"; B$
 INPUT "ENTER THIRD STRING"; C$
 IF LEN(A$) < LEN(B$) AND LEN(A$) < LEN(C$) THEN
 S$ = A$
 IF LEN(B$) < LEN(A$) AND LEN(B$)< LEN(C$) THEN
 S$ = B$
 ELSE
 S$ = C$
 END IF
 PRINT "SHORTEST STRING="; S$
 END

Q.10) WAP to ask number and find product of odd digits.


 CLS
 INPUT "ENTER ANY NUMBER"; N
 P=1
 WHILE N <> 0
 R = N MOD 10
 IF R MOD 2 = 1 THEN P = P * R
 N = N \ 10
 WEND
 PRINT "PRODUCT OF ODD DIGITS"; P
 END

Q.11) WAP TO ENTER ANY DIGIT AND PRINT EVEN DIGITS.


 CLS
 INPUT "ENTER ANY NUMBER"; N
 PRINT "EVEN DIGITS ARE ";
 WHILE N <> 0
 R = N MOD 10
 IF R MOD 2 = 0 THEN PRINT R;
 N = N \ 10
 WEND
 END
Q.12) WAP to ask number and find sum of even digits
 CLS
 INPUT "ENTER ANY NUMBER"; N
 S=0
 WHILE N < > 0
 R = N MOD 10
 IF R MOD 2 = 0 THEN S = S + R
 N = N \\ 10
 WEND
 PRINT "SUM OF EVEN DIGITS"; S
 END

Q.13) WAP to print the sum of the numbers between 3 to 30


 CLS
 FOR I = 3 TO 30
 S=S+I
 NEXT I
 PRINT “SUM OF NUMBERS BETWEEN 3 TO 30” ; S
 END

Q.12) WAP to generate 7 22 11 34……………19th terms

 CLS
 A=9
 FOR I = 1 TO 10
 PRINT A;
 IF A MOD 2 = 0 THEN
 A=A\2
 ELSE
 A=A*3+1
 END IF
 NEXT I
 END

Q,13) WAP to ask any string and check whether the first character of a ask string is alphabet
number or symbol

 CLS
 INPUT "ENTER ANY STRING"; S$
 A$ = LEFT$(S$, 1)
 B = ASC(A$)
 IF B >= 48 AND B <= 57 THEN
 CK$ = "FIRST CHARACTER IS A NUMBER"
 ELSEIF B >= 65 AND B <= 90 OR B >= 97 AND B <= 122 THEN
 CK$ = "FIRST CHARACTER IS ALPHABET"
 ELSE
 CK$ = "FIRST CHARACTER IS SYMBOL"
 END IF
 PRINT CK$
 END
Q.14) WAP to ask any string and reverse it.
 CLS
 INPUT "ENTER ANY STRING"; S$
 FOR I = LEN(S$) TO 1 STEP -1
 B$ = MID$(S$, I, 1)
 W$ = W$ + B$
 NEXT I
 PRINT "REVERSED STRING IS "; W$
 END

Q.15) WAP to enter any 10 numbers and sort in descending order.


 CLS
 DIM N(10)
 FOR I = 1 TO 10
 INPUT "ENTER THE NUMBERS"; N(I)
 NEXT I
 FOR I = 1 TO 10
 FOR J = 1 TO 10 - I
 IF N(J) < N(J + 1) THEN SWAP N(J), N(J + 1)
 NEXT J
 NEXT I
 PRINT "NUMBERS ARRANGED IN DESCENDING ORDER"
 FOR I = 1 TO 10
 PRINT N(I)
 NEXT I

Q.16) WAP to input any number and check whether the given no. is positive, negative or
zero.
 CLS
 INPUT “ENTER ANY NUMBER”; N
 IF N > 0 THEN
 PRINT N; IS POSITIVE NUMBER”
 ELSEIF N < 0 THEN
 PRINT N; IS NEGATIVE NUMBER”
 ELSE
 PRINT N; IS ZERO”
 END IF
 END

Q.17) WAP to print all odd numbers from 1 to 100 in descending order

 CLS
 FOR I = 99 TO 1 STEP - 2
 PRINT I,
 NEXT I
 END
Q.18) WAP to input the age of a person and find out whether the person is eligible to
vote or not.
 CLS
 INPUT “ENTER YOUR AGE”; A
 IF A >= 18 THEN
 PRINT “YOU ARE ELIGIBLE TO VOTE”
 ELSE
 PRINT “ YOU ARE NOT ELIGIBLE TO VOTE”
 END IF
 END

Q.19) WAP TO PRINT H.C.F AND L.C.M OF ANY TWO Given NUMBERS by user
 CLS
 INPUT "ENTER ANY TWO NUMBERS"; A, B
 C=A
 D=B
 WHILE A MOD B < > 0
 T = A MOD B
 A=B
 B=T
 WEND
 L=C*D/B
 PRINT "H.C.F="; B
 PRINT "L.C.M="; L
 END

Q.20) WAP to convert decimal number to hexadecimal number


 CLS
 INPUT "ENTER DECIMAL NUMBER"; D
 WHILE D < > 0
 R = D MOD 16
 IF R < 10 THEN
 S$ = STR$(R) + S$
 ELSE
 S$ = CHR$(R + 55) + S$
 END IF
 D = D \ 16
 WEND
 PRINT "HEXADECIMAL EQUIVALENT VALUE="; S$
 END

Q.21) WAP to ask any number and print the prime factors
 CLS
 INPUT "ENTER ANY TWO NUMBERS"; A, B
 WHILE A MOD B < > 0
 T = A MOD B
 A=B
 B=T
 WEND
 PRINT "H.C.F="; B
 END
Q.22) WAP to input a mark in a subject of a student and check if the student is pass or
nor.
 CLS
 INPUT”ENTER THE MARKS IN ANY SUBJECT”;A
 IF A>40 THEN
 PRINT” YOU ARE PASS”
 ELSE
 PRINT”YOU ARE FAIL”
 END

Q.23) WAP to ask number and find product of digits


 INPUT "ENTER ANY NUMBER"; N
 P=1
 WHILE N < > 0
 R = N MOD 10
 P=P*R
 N = N \ 10
 WEND
 PRINT "PRODUCT OF DIGITS"; P
 END

Q.24) WAP to ask number and find sum of square of odd digits
 CLS
 INPUT "ENTER ANY NUMBER"; N
 PRINT "SQUARE OF ODD DIGITS ARE ";
 WHILE N <> 0
 R = N MOD 10
 IF R MOD 2 = 1 THEN PRINT R ^ 2;
 N = N \ 10
 WEND
 END

Q.25) WAP to input any number and check whether the given no. is divisible by 3 and
7 or not.
 CLS
 INPUT “ENTER ANY NUMBER”; N
 IF N MOD 3 = 0 AND N MOD 7 = 0 THEN
 PRINT N; IS COMPLETELY DIVISIBLE BY 3 AND 7”
 ELSE
 PRINT N; IS NOT COMPLETELY DIVISIBLE BY 3 AND 7”
 END IF
 END

Q.26) WAP TO PRINT MULTIPLICATION TABLE OF A GIVEN NUMBER


 CLS
 INPUT "ENTER ANY NUMBER"; N
 FOR I = 1 TO 10
 PRINT N; "X"; I; "="; N * I
 NEXT I
 END

Q.27) WAP to input a year and display whether that year is a leap year or not .
 CLS
 INPUT “ENTER YEAR”; Y
 IF Y MOD 4 = 0 AND Y MOD 100 < > 0 OR Y MOD 400 = 0 THEN
 PRINT Y; IS LEAP YEAR”
 ELSE
 PRINT Y; IS NOT LEAP YEAR”
 END IF
 END

Q.28) WAP to convert hexadecimal number to decimal number.

 CLS
 INPUT "ENTER HEXADECIMAL NUMBER"; N$
 FOR I = LEN(N$) TO 1 STEP -1
 B$ = MID$(N$, I, 1)
 IF B$ = "A" THEN B$ = "10"
 IF B$ = "B" THEN B$ = "11"
 IF B$ = "C" THEN B$ = "12"
 IF B$ = "D" THEN B$ = "13"
 IF B$ = "E" THEN B$ = "14"
 IF B$ = "F" THEN B$ = "15"
 S = S + VAL(B$) * 16 ^ P
 P=P+1
 NEXT I
 PRINT "DECIMAL EQUIVALENT VALUE="; S
 END

Q.29) WAP to enter any 20 numbers and display the greatest one using array.

 REM
 CLS
 DIM N(20)
 FOR I = 1 TO 20
 INPUT "ENTER THE NUMBERS"; N(I)
 NEXT I
 G = N(1)
 FOR I = 2 TO 20
 IF N(I) > G THEN G = N(I)
 NEXT I
 PRINT “THE GREATEST NUMBER IS”; G
 END

Q.30) WAP to divide a number by another number and find the quotient and
remainder.
 CLS
 INPUT "ENTER FIRST NUMBER"; A
 INPUT "ENTER SECOND NUMBER"; B
 IF A > B THEN
 R = A MOD B
 Q=A\B
 ELSE
 R = B MOD A
 Q=B\A
 END IF
 PRINT "QUOTIENT="; Q
 PRINT "REMAINDER ="; R
 END

You might also like