Qbasic programs solutions(part 9) for class 8, class 9 and class 10

Codynn
12 Min Read
qbasic programs for class 8,9 and 10 part 9

Here, I have listed some of the qbasic programs.

161  Write a program in qbasic to ask number and find sum of cube 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 ^ 3 
N = N \ 10 
WEND 
PRINT "SUM OF CUBE OF EVEN DIGITS"; S 
END 
  • Algorithm
  • Explanation

Here’s the algorithm of above program:

1. Start

2. Clear the screen

3. Ask the user to input any number and store it as ‘N’

4. Set a variable ‘S’ to 0

5. While ‘N’ is not equal to 0, do the following:
a. Find the last digit of ‘N’ and store it as ‘R’
b. If ‘R’ is even, cube it and add the result to ‘S’
c. Remove the last digit from ‘N’

6. Print the sum of the cubes of even digits stored in ‘S’

7. End

Here is the explanation:

1. CLS: This command clears the screen, ensuring a clean slate for output.

2. INPUT "ENTER ANY NUMBER"; N: This line prompts the user to enter any number and stores the input in the variable N.

3. S = 0: This initializes a variable S to store the sum of the cubes of even digits later in the program.

4. WHILE N <> 0: This line starts a loop that continues as long as the value of N is not equal to 0. The loop will execute the code block that follows until N becomes 0.

5. R = N MOD 10: This line calculates the remainder (R) when the input number (N) is divided by 10. This gives the last digit of the number.

6. IF R MOD 2 = 0 THEN S = S + R ^ 3: This line checks if the last digit (R) is even (i.e., divisible by 2). If it is, then it cubes the digit (R) and adds it to the variable S.

7. N = N \ 10: This line updates the value of N by removing its last digit. This is achieved by integer division (\) by 10, which effectively removes the last digit from the number.

8. WEND: This keyword marks the end of the WHILE loop. It indicates that the program should return to the beginning of the loop and repeat the process as long as the condition (N <> 0) is true.

9. PRINT "SUM OF CUBE OF EVEN DIGITS"; S: After the loop completes, this line prints the sum of the cubes of the even digits calculated during the loop.

10. END: This marks the end of the program execution.

In summary, this program takes an input number, iterates through its digits, calculates the cube of each even digit, and finally prints the sum of these cubes.

162  Write a program in qbasic TO ENTER ANY DIGIT AND PRINT ODD DIGITS    

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

163  Write a program to enter any three numbers and display the greatest one.    

CLS 
INPUT “ENTER ANY THREE NUMBERS”; A, B, 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 

164  Write a program in QBasic to ask any string and count total no. of vowels consonants and words    

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 
END 

165  Write a program in qbasic that reads six numbers from the list and prints sum of those numbers. The list of number contains: 9   6   93   25    

DATA 9,6,93,25 
FOR P = 1 TO 4 STEP 1 
    READ w 
    sum = sum + w 
NEXT P 
PRINT sum 
END 

166  Write a program in qbasic to generate the series 2   2   4   6   10…………13th term    

CLS 
A = 2 
B = 2 
FOR I = 1 TO 13 
PRINT A; 
C = A + B 
A = B 
B = C 
NEXT I 
END 

167  Write a program in qbasic to generate the following series 13579   1357   135   13   1    

CLS 
FOR I = 9 TO 1 STEP -2 
FOR J = 1 TO I STEP 2 
PRINT J; 
NEXT J 
PRINT 
NEXT I 
END 

168  Write a program in qbasic to print numbers 30   28   5   27   25   5……   9th terms    

CLS 
A = 30 
FOR I = 1 TO 9 
PRINT A, 
A = A – 1.5 
NEXT I 
END 


169  Write a program in qbasic to print first 5 Armstrong numbers    

CLS 
N = 1 
CNT = 1 
TOP: 
A = N 
S = 0 
WHILE A <> 0 
R = A MOD 10 
S = S + R ^ 3 
A = A \ 10 
WEND 
IF N = S THEN 
PRINT N, 
CNT = CNT + 1 
END IF 
N = N + 1 
IF CNT <= 5 THEN GOTO TOP 
END 
 

170  Write a program in qbasic to ask string and find whether the first character is a number or uppercase or lowercase    

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 THEN 
CK$ = "FIRST CHARACTER IS UPPERCASE" 
ELSE IF  B > 97 AND B < 122 THEN 
CK$ = "FIRST CHARACTER IS LOWERCASE" 
ELSE 
CK$=”FIRST CHARACTER IS NEITHER NUMBER, UPPERCASE OR LOWERCASE” 
END IF 
PRINT CK$ 
END 


171  Write a program in qbasic to count the frequency of characters R or S present in the supplied string    

CLS 
INPUT "ENTER ANY STRING"; S$ 
RC = 0 
SC = 0 
FOR I = 1 TO LEN(S$) 
B$ = MID$(S$, I, 1) 
C$ = UCASE$(B$) 
IF C$ = "R" THEN RC = RC + 1 
IF C$ = "S" THEN SC = SC + 1 
NEXT I 
PRINT "TOTAL NO. OF R= "; RC 
PRINT "TOTAL NO. OF S= "; SC 
END 

172  Write a program in qbasic to generate the following series 123456789   1234567   12345   123   1    

CLS 
A# = 123456789 
FOR I = 1 TO 5 
PRINT A# 
A# = A# \ 100 
NEXT I 
END

173  Write a program in qbasic to print cube of an ask number    

REM PROGRAM TO DISPLAY CUBE OF AN INPUT NUMBER 
CLS 
INPUT “ENTER ANY NUMBER”; N 
C = N ^ 3 
PRINT “CUBE OF NUMBER ”; C 
END 


174  WRITE A PROGRAM IN QBASIC to ask number and find sum of digits    

CLS 
INPUT "ENTER ANY NUMBER"; N 
S = 0 
WHILE N <> 0 
R = N MOD 10 
S = S + R 
N = N \ 10 
WEND 
PRINT "SUM OF DIGITS"; S 
END 

175  Write a program 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 

176  Write a program in qbasic to ask any string and count total no. of sentences    

CLS 
INPUT "ENTER ANY STRING"; S$ 
SC = 0 
FOR I = 1 TO LEN(S$) 
B$ = MID$(S$, I, 1) 
IF B$ = " " THEN 
SC = SC + 1 
END IF 
NEXT I 
PRINT "TOTAL NO. OF SENTENCES= "; SC 
END 


177  Write a program in qbasic to generate the following series 2   4   6   8…………12th term    

CLS 
A = 2 
FOR I = 1 TO 12 
PRINT A, 
A = A + 2 
NEXT I 
END 

178  Write a program in qbasic 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 

179  Write a program in qbasic using to print first 19 even numbers    

CLS 
A = 2 
FOR I = 1 TO 19 
PRINT A, 
A = A+ 2 
NEXT I 
END  

180  Write a program in qbasic to generate the series 1   8   27……………8th   

 

CLS 
FOR I = 1 TO 8 
PRINT I ^ 3, 
NEXT I 
END 


We also have mobile app where you can view all the qbasic programs. For better experience I highy recommend you to use our mobile app

Please download our app by clicking the image below:

Please download our app by clicking the image below:

Download Qbasic application on your phone
Download Qbasic application on your phone

If the above link is not working. You can use this link –> https://play.google.com/store/apps/details?id=com.allbachelor.qbasicapp

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *