Computer Gwbasic
Computer Gwbasic
CLASS 7
GWBASIC PROGRAMS
Session: 2024-25
2. WAP to input any three numbers and display the greatest number.
3. WAP to input the rainfall amount of a city and display suitable message as follows:
Rainfall amount(cm) Message
<10 Very less
>=10 and <20 Normal
>=20 Heavy
4. WAP to enter the weekly sales of a salesman and calculate and display his commission
as follows:
Sales(Rs) Commission(% of Sales)
<5000 5
>=5000 and <20000 10
>=20000 15
Page 1 of 15
10 INPUT “ENTER WEEKLY SALES”;S
20 IF S<5000 THEN CP=5
30 IF S>=5000 AND S<20000 THEN CP=10
40 IF S>=20000 THEN CP=15
50 C=S*CP/100
60 PRINT “COMMISSION=”;C
70 END
5. A student can enter the Talent Search Competition if he is either 15 years of age or
above, or he has completed class 8. WAP to accept name, age and class of a student and
display whether he can take part in the competition or not.
6. WAP to input the angle and print whether it an acute, obtuse or right angle.
7. WAP to input three sides of a triangle and check and display whether it is equilateral,
isosceles or scalene triangle.
8. WAP to enter three angles of a triangle and check and display if it is right angled
triangle or not.
9. WAP input the name, age and salary of a person, calculate and display the Insurance
premium as follows:
Age(Years) Premium(% of salary)
20-35 8
36-50 10
51 and above 14
Page 2 of 15
10 INPUT “ENTER NAME, AGE SALARY”;N$,A,S
20 IF A<=20 AND A<=35 THEN PP=8
30 IF A>=36 AND A<=50 THEN PP=10
40 IF A>=51 THEN PP=14
50 P=S*PP/100
60 PRINT “PREMIUM=’;P
70 END
10. WAP to input the number of units consumed and display the electric bill according to
the following criteria:
No of units Rs/Unit
<=100 5
>100 and <=200 6
>200 7
Moreover, every customer has to pay rupees 50 as meter rent.
10 FOR I=1 TO 10
20 PRINT I;”/”;10^I
30 NEXT I
40 END
10 FOR I=-5 TO 5
20 PRINT I^2
30 NEXT I
40 END
10 FOR I=1 TO 10
20 PRINT I^2-1
30 NEXT I
40 END
14. WAP to display the series: 1/1, 1/3, 1/5, 1/7 , …. 1/N
10 INPUT N
20 FOR I=1 TO N STEP 2
30 PRINT 1;”/”;I
Page 3 of 15
40 NEXT I
50 END
15. WAP to display the series: 1/1, 4/8, 9/27, 16/64 …… N terms.
10 INPUT N
20 FOR I=1 TO N
30 PRINT I^2;”/”;I^3
40 NEXT I
50 END
16. WAP to input any 20 numbers and count and display how many are even and odd.
10 EV=0:OD=0
20 FOR I=1 TO 20
30 INPUT M
40 IF M MOD 2=0 THEN EV=EV+1 ELSE OD=OD+1
50 NEXT I
60 PRINT “EVEN NUMBERS=”;EV
70 PRINT “ODD NUMBERS=”;OD
80 END
17. WAP to input any 20 numbers and count and display how many are negative, positive
or zero.
10 NE=0:PO=0:ZE=0
20 FOR I=1 TO 20
30 INPUT M
40 IF M<0 THEN NE=NE+1
50 IF M>0 THEN PO=PO+1
60 IF M=0 THEN ZE=ZE+1
70 NEXT I
80 PRINT “NEGATIVE NUMBERS=”;NE
90 PRINT “POSITIVE NUMBERS=”;PO
100 PRINT “ZEROS=”;ZE
110 END
18. WAP to input the total number of students in a class also their gender code, M for male
and F for female. Now count and display the number of boys and girls present in the
class.
10 B=0:G=0
20 INPUT “ENTER NUMBER OF STUDENTS”;N
30 FOR I=1 TO N
40 INPUT “ENTER GENDER CODE(M/F)”;G$
50 IF G$=”M” THE B=B+1
60 IF G$=”F” THEN G=G+1
70 NEXT I
80 PRINT “NUMBER OF BOYS=”;B
90 PRINT “NUMBER OF GIRLS=”;G
Page 4 of 15
100 END
19. WAP to enter the marks and rank of N students in a class, count and display the
number of students getting scholarship. The criteria to get scholarship is marks>=80 or
rank=”FIRST”.
10 S=0
20 INPUT N
30 FOR I=1 TO N
40 INPUT “ENTER MARKS AND RANK”;M,R$
50 IF M>=80 OR R$=”FIRST” THE S=S+1
60 NEXT I
70 PRINT “NUMBER OF STUDENTS GETTING SCHOLARSHIP=”;S
80 END
20. Write a program to input grade of all the students in your class, count and display the
frequency of each grade as follows:
Grade A Grade B Grade C Grade D
? ? ? ?
10 A=0:B=0:C=0:D=0
20 INPUT “ENTER NUMBER OF STUDENTS’;N
30 FOR I=1 TO N
40 INPUT “ENTER GRADE”;G$
50 IF G$=”A” THEN A=A+1
60 IF G$=”B” THEN B=B+1
70 IF G$=”C” THEN C=C+1
80 IF G$=”D” THEN D=D+1
90 NEXT I
100 PRINT “GRADE A”,”GRADE B”,”GRADE C”,”GRADE D”
110 PRINT A,B,C,D
120 END
21. WAP to enter the computer marks of all the students in your class and prepare the
frequency table based on the following slab:
% MARKS NO OF STUDENTS
Below 40 ?
>=40 and <60 ?
>=60 and <80 ?
>=80 and <=100 ?
10 C1=0:C2=0:C3=0:C4=0
20 INPUT “ENTER NUMBER OF STUDENTS”;N
30 FOR I=1 TO N
40 INPUT “ENTER COMPUTER MARKS”;M
50 IF M<40 THEN C1=C1+1
60 IF M>=40 AND M<60 THEN C2=C2+1
70 IF M>=60 AND M<80 THEN C3=C3+1
80 IF M>=80 AND M<=100 THEN C4=C4+1
90 NEXT I
Page 5 of 15
100 PRINT “% MARKS”, “NO OF STUDENTS”
110 PRINT “Below 40”, C1
120 PRINT “>=40 and <60”, C2
130 PRINT “>=60 and <80”, C3
140 PRINT “>=80 and <=100”, C4
150 END
22. WAP to input a number, check and display if it is perfect square or not.
23. WAP to input a number and check and display if it is prime or not. Hints: A prime
number is a number which is divisible by only 1 and itself.
10 C=0
20 INPUT “ENTER A NUMBER”;N
30 FOR I=1 TO N
40 IF N MOD I=0 THEN C=C+1
50 NEXT I
60 IF C=2 THEN PRINT “PRIME NUMBER” ELSE PRINT “NOT A PRIME NUMBER”
70 END
24. WAP to input any 20 numbers and display the numbers which are divisible by 5.
10 FOR I=1 TO 20
20 INPUT N
30 IF N MOD 5=0 THEN PRINT N
40 NEXT I
50 END
25. Write a program to enter any 50 numbers and display their absolute values.
10 FOR I=1 TO 50
20 INPUT N
30 PRINT ABS(N)
40 NEXT I
50 END
26. WAP to input number of days and convert it into years, months and days.
Page 6 of 15
60 PRINT Y; “YEARS”;M;”MONTHS”;D;”DAYS”
70 END
27. WAP to enter n numbers and display the square root of them.
28. WAP to enter any n numbers and display integer parts only.
29. Write a program to store the number 789 in a variable and display the reverse of it.
[Hints : Reverse is 987].
10 CLS
20 N=789
30 R1=N MOD 10
40 N=INT(N/10)
50 R2=N MOD 10
60 N=INT(N/10)
70 R=R1*100+R2*10+N
80 PRINT “REVERSE=”;R
90 END
30. WAP to enter any three digit number n. Display the sum of all its digits. [ Hints: Input
is 546, Output is 5+4+6=15].
10 CLS
20 INPUT “ENTER A THREE DIGIT NUMBER”;N
30 R1=N MOD 10
40 N=INT(N/10)
50 R2=N MOD 10
60 N=INT(N/10)
90 S=R1+R2+N
100 PRINT “SUM OF DIGITS =’;S
110 END
Page 7 of 15
FINAL TERM SYLLABUS:
For Loop with accumulators
String Functions LEN, RIGHT, LEFT, MID (without FOR loop)
String Concatenation
(1st Term syllabus to be included)
10 CLS : S=0
20 INPUT “ENTER VALUES OF A AND N”;A, N
30 FOR I=1 TO N
40 S=S+A^I
50 NEXT I
60 PRINT “SUM = ”;S
70 END
10 CLS
20 S=0
30 INPUT “ENTER VALUES OF A AND N”;A,N
40 FOR I=1 TO N
50 S=S+A^I/I
60 NEXT I
70 PRINT “SUM=”;S
80 END
3. WAP to display the sum of the series: a/b2 + a2/b3 + a3/b4 +… + an/bn+1
10 S=0
20 INPUT “ENTER VALUES OF A , B AND N”;A,B,N
30 FOR I=1 TO N
40 S=S+A^I/B^(I+1)
50 NEXT I
60 PRINT “SUM=”;S
70 END
4. WAP to display the sum of the series: a/3 + a2/6 + a3/9 + …. aN/(N*3)
10 S=0
20 INPUT “ENTER VALUES OF A AND N”;A,N
30 FOR I=1 TO N
40 S=S+A^I/(I*3)
50 NEXT I
60 PRINT “SUM=”;S
70 END
Page 8 of 15
5. WAP to display the sum of the series: 4 + 16 + 36 + 64 + …. N terms.
10 S=0
20 INPUT “ENTER VALUE OF N”;N
30 FOR I=2 TO N*2 STEP 2
40 S=S+I^2
50 NEXT I
60 PRINT “SUM=”;S
70 END
10 S=0
20 INPUT “ENTER VALUE OF N”;N
30 FOR I=1 TO N
40 S=S+I^3
50 NEXT I
60 PRINT “SUM=”;S
70 END
10 P=0:S=0
20 INPUT “ENTER VALUE OF N”;N
30 FOR I=1 TO N
40 P=P*10+9
50 S=S+P
60 NEXT I
70 PRINT “SUM=”;S
80 END
10 P=0:S=0
20 INPUT “ENTER VALUE OF N”;N
30 FOR I=1 TO N
40 P=P*10+I
50 S=S+P
60 NEXT I
70 PRINT “SUM=”;S
80 END
9. WAP to display the sum of the series: 1 + 2/4 + 3/9 + 4/16 + …. N/N^2
10 S=0
20 INPUT “ENTER VALUE OF N”;N
30 FOR I=1 TO N
40 S=S+I/(I^2)
50 NEXT I
60 PRINT “SUM=”;S
Page 9 of 15
70 END
10. WAP to display the sum of the series: 1*2 + 2*3 + 3*4 + …. + N*(N+1)
10 S=0
20 INPUT “ENTER VALUE OF N”;N
30 FOR I=1 TO N
40 S=S+I*(I+1)
50 NEXT I
60 PRINT “SUM=”;S
70 END
11. WAP to display the sum of the series: 1 + (1*2) + (1*2*3) + (1*2*3*4) + …. N terms
10 P=1:S=0
20 INPUT “ENTER VALUE OF N”;N
30 FOR I=1 TO N
40 P=P*I
50 S=S+P
60 NEXT I
70 PRINT “SUM=”;S
80 END
12. WAP to input A and B and display the sum of all the even numbers and product of all
the odd numbers from A to B.
13. WAP to enter any n numbers (positive or negative) and display the sum of the absolute
values of them.
10 CLS : S=0
20 INPUT “ENTER N”; N
30 FOR I=1 TO N
40 INPUT “ENTER A NUMBER”;M
50 S=S+ABS(M)
60 NEXT I
70 PRINT “SUM=”;S
80 END
Page 10 of 15
14. WAP to input a number and display its factorial. Ex: Factorial of 4=4x3x2x1=24.
10 CLS : F=1
20 INPUT N
30 FOR I=N TO 1 STEP -1
40 F=F*I
50 NEXT I
60 PRINT “FACTORIAL=”;F
70 END
15. WAP to enter A and B, now display the sum and average of all the natural numbers
from A to B.
10 CLS : S=0
20 INPUT “ENTER A AND B”;A,B
30 FOR I=A TO B
40 S=S+I
50 NEXT I
60 AVG=S/(B-A+1)
70 PRINT “SUM OF ALL THE NUMBERS=”;S
80 PRINT “AVERAGE OF ALL THE NUMBERS=”;AVG
90 END
16. WAP to enter the individual runs scored by 11 players in a cricket match. Now display
their total and average runs scored.
10 CLS
20 S=0
30 FOR I=1 TO 11
40 INPUT “ENTER THE RUN”;R
50 S=S+R
60 NEXT I
70 AVG=S/11
80 PRINT “TOTAL RUN SCORED=”;S
90 PRINT “AVERAGE RUN SCORED =”;AVG
100 END
17. WAP to enter any N numbers from the user, divide them by 5 and display the sum of all
the quotients.
10 CLS : S=0
20 INPUT “ENTER N”;N
30 FOR I=1 TO N
40 INPUT “ENTER A NUMBER”;M
50 S=S+INT(M/5)
60 NEXT I
70 PRINT “SUM=”;S
80 END
Page 11 of 15
18. In a courier service the charges for the parcels are as follows:
Parcel weight(Gram) Rs/Gram
<=200 0.5
>200 and <=500 1.0
>500 1.5
Write a program to input parcel weight in grams for N number of customers and
display the total charges collected by the courier service.
10 CLS : T=0
20 INPUT “ENTER NUMBER OF CUSTOMERS”;N
30 FOR I=1 TO N
40 INPUT “ENTER PARCEL WEIGHT IN GRAMS”;W
50 IF W<=200 THEN R=0.5
60 IF W>200 AND W<=500 THEN R=1.0
70 IF W>500 THEN R=1.5
80 C=W*R
90 T=T+C
100 NEXT I
110 PRINT “TOTAL CHARGES COLLECTED=”;T
120 END
19. A shopkeeper gives discount on purchase of items from his shop according to the
following criteria:
Purchase Amount(Rs) Discount(%)
<=1000 5
>1000 and <=2000 10
>2000 15
WAP to enter the purchase amount for N number of customers and display amount to
be paid after getting the discount. Also display the total amount earned by the
shopkeeper from all the customers.
10 CLS : T=0
20 INPUT “ENTER NUMBER OF CUSTOMERS”;N
30 FOR I=1 TO N
40 INPUT “ENTER PURCHASE AMOUNT”;P
50 IF P<=1000 THEN DP=5
60 IF P>1000 AND P<=2000 THEN DP=10
70 IF P>2000 THEN DP=15
80 D=P*DP/100
90 AMT=P-D
100 PRINT “AMOUNT TO BE PAID=”;AMT
110 T=T+AMT
120 NEXT I
130 PRINT “TOTAL AMOUNT EARNED BY THE SHOPKEEPER=”;T
140 END
Page 12 of 15
20. WAP to store the sentence “SLOW AND STEADY WINS THE RACE” in proper
variable. Now using string functions display the following output:
SLOW
STEADY
RACE
21. WAP to store the word “UNIFORM RESOURCE LOCATER” in a variable and
display the following output using string functions.
UNIFORM
RESOURCE
LOCATER
URL
22. WAP to store the word “MOUSE” in a variable and display the following pattern based
on string functions, without using any loop :
MOUSE
MOUS
MOU
MO
M
10 A$=”MOUSE”
20 PRINT LEFT$(A$,5)
30 PRINT LEFT$(A$,4)
40 PRINT LEFT$(A$,3)
50 PRINT LEFT$(A$,2)
60 PRINT LEFT$(A$,1)
70 END
Page 13 of 15
23. WAP to enter your first name, middle name and last name, and display it in the
following format:
Example: INPUT: ABDUL KALAM AZAD
OUTPUT:
A. K. AZAD
AZAD A. K.
A. K. A.
25. WAP to input two different words and display total number of characters present in
them.
26. WAP to enter today’s date in the dd/mm/yyyy format and print only dd/mm, dd/yyyy,
mm/yyyy.
Page 14 of 15
27. WAP to store the word “ACKNOWLEDGEMENT” in a suitable variable and using
string function display “KNOW”, “NOW”, “KNOWLEDGE”from it.
10 A$=“ACKNOWLEDGEMENT”
20 PRINT MID$(A$,3,4)
30 PRINT MID$(A$,4,3)
40 PRINT MID$(A$,3,9)
50 END
28. WAP to input two different words from the user, concatenate and store them into a
third variable, now display it. Also display the length of the new word formed.
29. WAP to input a name, check and display if it starts with vowel or consonant.
30. WAP to enter a name and a number N, now extract N characters from the left and the
right side of the name, concatenate and display it.
*****
Page 15 of 15