GW-BASIC Programs for School Syllabus

Write a program to ADD two numbers
10 REM ADD TWO NUMBERS
20 INPUT “ENTER A”;A
30 INPUT “ENTER B”;B
40 LET C=A+B
50 PRINT “SUM”;C
60 END

Write a program to SUBTRACT two numbers
10 REM SUBTRACT TWO NUMBERS
20 INPUT “ENTER A”;A
30 INPUT “ENTER B”;B
40 LET C=A-B
50 PRINT “DIFFERENCE”;C
60 END

Write a program to calculate the AREA OF RECTANGLE
10 REM AREA OF RECTANGLE
20 INPUT “ENTER LENGTH”;L
30 INPUT “ENTER BREADTH”;B
40 LET A=L*B
50 PRINT “AREA”;A
60 END

Write a program to calculate the AREA OF CIRCLE
10 REM AREA OF CIRCLE
20 INPUT “ENTER RADIUS”;R
30 A=3.142*R*R
40 PRINT “AREA”;A
50 END

Write a program to calculate the AREA OF TRIANGLE
10 REM AREA OF TRIANGLE
20 INPUT “ENTER LENGTH”;L
30 INPUT “ENTER BREADTH”;B
40 LET A=0.5*L*B
50 PRINT “AREA”;A
60 END

Write a program to calculate the SUM and AVERAGE of three marks and display them
10 REM SUM AND AVERAGE
20 INPUT “MARK1”;M1
30 INPUT “MARK2”;M2
40 INPUT “MARK3”;M3
50 T=M1+M2+M3
60 A=T/3
70 PRINT “TOTAL”;T
80 PRINT “AVERAGE”;A
90 END

Write a program  to calculate the profit if cost price and selling
price is given by user
10 REM CALCULATE PROFIT
20 INPUT “ENTER SELLING PRICE”;SP
30 INPUT “ENTER COST PRICE”;CP
40 LET P=SP-CP
50 PRINT “PROFIT”;P
60 END

Write a program  to calculate the profit and profit percentage if cost
price and selling price is given by user
10 REM CALCULATE PROFIT AND PROFIT PERCENTAGE
20 INPUT “ENTER SELLING PRICE”;SP
30 INPUT “ENTER COST PRICE”;CP
40 LET P=SP-CP
50 LET PP=P/CP*100
60 PRINT “PROFIT”;P
70 PRINT “PROFIT PERCENTAGE”;PP
80 END

Write a program  to calculate the SIMPLE INTEREST for a given
Principal, Rate and Time
10 REM TO CALCULATE SIMPLE INTEREST
20 INPUT “PRINCIPAL”;P
30 INPUT “RATE”;R
40 INPUT “TIME”;T
50 I=P*R*T/100
60 PRINT “SIMPLE INTEREST”;I
70 END

Write a program  to find the SQUARE and CUBE of a Given Number
10 REM SQUARE AND CUBE
20 INPUT “NUMBER”;N
30 S=N^2
40 C=N^3
50 PRINT “SQUARE”;S
60 PRINT “CUBE”;C
70 END

Write a program to check whether a person is eligible to vote or not
10 REM ELIGIBLE TO VOTE OR NOT
20 INPUT “ENTER AGE”;A
30 IF A>=18 THEN PRINT “ELIGIBLE TO VOTE” ELSE PRINT “NOT ELIGIBLE TO VOTE”
40 END

Write a program to check whether a NUMBER is ODD or EVEN
10 REM NUMBER ODD OR EVEN
20 INPUT “ENTER NUMBER”;N
30 IF N MOD 2=0 THEN PRINT “EVEN” ELSE PRINT “ODD”
40 END

Write a program to check whether a YEAR is a LEAP YEAR or NOT
10 REM LEAP YEAR OR NOT
20 INPUT “ENTER NUMBER”;N
30 IF N MOD 4=0 THEN PRINT “LEAP YEAR” ELSE PRINT “NOT A LEAP YEAR”
40 END

Write a program to check whether a number is divisible by 5 or not
10 REM DIVISIBLE BY 5 OR NOT
20 INPUT “ENTER NUMBER”; N
30 IF N MOD 5=0 THEN PRINT “DIVISIBLE BY 5” ELSE PRINT “NOT DIVISIBLE BY 5”
40 END

Write a program to check whether a number is divisible by 5 OR 7 or not
10 REM DIVISIBLE BY 5 OR NOT
20 INPUT “ENTER NUMBER”;N
30 IF N MOD 5=0 OR N MOD 7=0 THEN PRINT “DIVISIBLE BY 5 OR 7” ELSE
PRINT “NOT DIVISIBLE BY 5 OR 7”
40 END

Write a program to find the largest side of  a Triangle
10 REM LARGEST SIDE OF TRIANGLE
20 INPUT “SIDE 1”;S1
30 INPUT “SIDE 2”;S2
40 INPUT “SIDE 3”;S3
50 IF S1>S2 AND S1>S3 THEN PRINT “A IS THE GREATEST SIDE”
60 IF S2>S3 AND S2>S1 THEN PRINT “B IS THE GREATEST SIDE”
70 IF S3>S2 AND S3>S1 THEN PRINT “C IS THE GREATEST SIDE”
80 END

Write a program to check whether the person has passed or failed on
the marks of three subjects. If m1>=40 and m2>=40 and m3>=40 then print “PASS” else print “FAIL”
10 REM PASS OR FAIL
20 INPUT “MARK 1”;M1
30 INPUT “MARK 2”;M2
40 INPUT “MARK 3”;M3
50 IF M1>=40 AND M2>=40 AND M3>=40 THEN PRINT “PASS” ELSE PRINT “FAIL”
60 END

Write a program to accept a number and check whether it is a negative number, zero or positive number
10 REM NEGATIVE, ZERO, POSITIVE
20 INPUT “NUMBER”;N
30 IF N<0 THEN PRINT “NEGATIVE”
40 IF N=0 THEN PRINT “ZERO”
50 IF N>=0 THEN PRINT “POSITIVE”
60 END

Write a program to CHECK whether the person has made profit, loss, no profit no loss
10 REM CHECK WHETHER HE HAS MADE PROFIT, LOSS, NO PROFIT NO LOSS
20 INPUT “ENTER SELLING PRICE”; SP
30 INPUT “ENTER COST PRICE”; CP
40 IF SP>CP THEN PRINT “PROFIT”
50 IF CP>SP THEN PRINT “LOSS”
60 IF CP=SP THEN PRINT “NO PROFIT NO LOSS”
70 END

Write a program to generate natural number from 1 to 10 using IF
10 REM GENERATE NATURAL NUMBERS FROM 1 TO 10
20 I=1
30 IF I <=10 THEN PRINT I ELSE GOTO 60
40 I=I+1
50 GOTO 30
60 END

Write a program to generate natural number from 1 to 10 using WHILE
10 REM GENERATE NATURAL NUMBERS FROM 1 TO 10
20 I=1
30 WHILE I<=10
40 PRINT I
50 I=I+1
60 WEND
70 END

Write a program to generate natural number from 1 to 10 using FOR
10 REM GENERATE NATURAL NUMBERS FROM 1 TO 10
20 FOR I=1 TO 10 STEP 1
30 PRINT I
40 NEXT I
50 END

Write a program to generate natural number from 1 to N using IF
10 REM GENERATE NATURAL NUMBERS FROM 1 TO N
20 I=1
30 INPUT “ENTER NUMBER”;N
40 IF I <=10 THEN PRINT N ELSE GOTO 70
50 I=I+1
60 GOTO 40
70 END

Write a program to generate natural number from 1 to N using WHILE
10 REM GENERATE NATURAL NUMBERS FROM 1 TO N
20 I=1
30 INPUT “ENTER NUMBER”;N
40 WHILE I<=N
50 PRINT I
60 I=I+1
70 WEND
80 END

Write a program to generate natural number from 1 to N using FOR
10 REM GENERATE NATURAL NUMBERS FROM 1 TO N
20 INPUT “ENTER NUMBER”;N
30 FOR I=1 TO N STEP 1
40 PRINT I
50 NEXT I
60 END

Write a program to generate the series 1,4,9,16……..N2
10 REM GENERATE SERIES 1,4,9,16……N*N
20 INPUT “ENTER NUMBER”;N
30 FOR I=1 TO N STEP 1
40 J=I*I
50 PRINT J
60 NEXT I
70 END

Write a program to generate the series 1,1,2,4,3,9,4,16……..N2
10 REM GENERATE SERIES 1,1,2,4,3,9,4,16……..N,N*N
20 INPUT “ENTER NUMBER”;N
30 FOR I=1 TO N STEP 1
40 J=I*I
50 PRINT I
60 PRINT J
70 NEXT I
80 END

Write a program to generate the even numbers from M to N
10 REM EVEN NUMBERS BETWEEN M TO N
20 INPUT “ENTER INITIAL VALUE”;M
30 INPUT “ENTER FINAL VALUE”;N
40 FOR I=M TO N STEP 1
50 IF I MOD 2=0 THEN PRINT I
80 NEXT I
90 END

Write a program to generate the MULTIPLES of 3 or 7 from M to N
10 REM EVEN NUMBERS BETWEEN M TO N
20 INPUT “ENTER INITIAL VALUE”;M
30 INPUT “ENTER FINAL VALUE”;N
40 FOR I=M TO N STEP 1
50 IF I MOD 3=0 OR I MOD 7=0 THEN PRINT I
80 NEXT I
90 END

Write a program to generate a multiplication table of N
10 REM GENERATE Multiplication Table of N
20 INPUT “ENTER NUMBER”;N
30 FOR I=1 TO 10 STEP 1
40 J=N*I
50 PRINT N,”*”,I,”=”,J
60 NEXT I
70 END

Write a program to generate even numbers of N Terms
10 REM GENERATE Even Numbers of N Terms
20 INPUT “ENTER NUMBER”;N
30 FOR I=2 TO N*2 STEP 2
40 PRINT I
50 NEXT I
60 END

10 REM GENERATE Even Numbers of N Terms
20 INPUT “ENTER NUMBER”;N
30 FOR I=1 TO N STEP 1
40 J=2*I
50 PRINT J
60 NEXT I
70 END

Write a program to find the sum of the series S=1+2+3+4….N
10 REM Sum of the series S=1+2+3+4+… N
20 INPUT “ENTER NUMBER”;N
30 S=0
40 FOR I=1 TO N STEP 1
50 S=S+I
60 NEXT I
70 PRINT “SUM”;S
80 END

Find the factorial of a given Number
10 REM Factorial of a given number
20 INPUT “ENTER NUMBER”;N
30 F=1
40 FOR I=1 TO N STEP 1
50 F=F*I
60 NEXT I
70 PRINT “Factorial”;F
80 END

Factors of a Given Number
10 REM Factors of a Given Number
20 INPUT “ENTER NUMBER”;N
30 FOR I=1 TO N STEP 1
40 IF N MOD I =0 THEN PRINT I
50 NEXT I
60 END

Check Whether the Given Number is Prime or Not
10 REM Prime or Not
20 INPUT “ENTER NUMBER”;N
30 LET C=0
40 FOR I=1 TO N STEP 1
50 IF N MOD I =0 THEN C=C+1
60 NEXT I
70 IF C=2 THEN PRINT “PRIME” ELSE PRINT “NOT PRIME”
80 END

Check Whether the Given Number is Perfect or Not
10 REM Perfect or Not
20 INPUT “ENTER NUMBER”;N
30 LET C=0
40 FOR I=1 TO N-1 STEP 1
50 IF N MOD I =0 THEN C=C+I
60 NEXT I
70 IF C=N THEN PRINT “PERFECT” ELSE PRINT “NOT PERFECT”
80 END

Count the Number of digits of a given number
10 REM Number of DIGITS
20 INPUT “ENTER NUMBER”;N
30 LET C=0
40 WHILE N>0
50 C=C+1
60 N=INT(N/10)
70 WEND
80 PRINT “Number of Digits”;C
90 END

Sum of Individual digits of a given number
10 REM SUM of DIGITS
20 INPUT “ENTER NUMBER”;N
30 LET S=0
40 WHILE N>0
50 J=N MOD 10
60 S=S+J
70 N=INT(N/10)
80 WEND
90 PRINT “Sum of Digits”;S
100 END

Product of Individual digits of a given number
10 REM PRODUCT of DIGITS
20 INPUT “ENTER NUMBER”;N
30 LET P=1
40 WHILE N>0
50 J=N MOD 10
60 P=P*J
70 N=INT(N/10)
80 WEND
90 PRINT “Product of Digits”;P
100 END

Reverse a Given Number
10 REM Reverse a Given Number
20 INPUT “ENTER NUMBER”;N
30 LET S=0
40 WHILE N>0
50 J=N MOD 10
60 S=S*10+J
70 N=INT(N/10)
80 WEND
90 PRINT “Reverse”;S
100 END

Armstrong Number or Not
10 REM Armstrong or Not
20 INPUT “ENTER NUMBER”;N
30 LET S=0
40 M=N
50 WHILE N>0
60 J=N MOD 10
70 S=S+J*J*J
80 N=INT(N/10)
90 WEND
100 IF S=M THEN PRINT “ARMSTRONG” ELSE PRINT “NOT ARMSTRONG”
110 END

Palindromic Number or Not
10 REM Palindromic or Not
20 INPUT “ENTER NUMBER”;N
30 LET S=0
40 M=N
50 WHILE N>0
60 J=N MOD 10
70 S=S*10+J
80 N=INT(N/10)
90 WEND
100 IF S=M THEN PRINT “PALINDROMIC” ELSE PRINT “NOT PALINDROMIC”
110 END

Generate Fibonacci series form 1,1,2,3,……144
10 LET F1=1
20 LET F2=1
30 LET F=0
40 PRINT F1
50 PRINT F2
60 WHILE F<144
70 F=F1+F2
80 PRINT F
90 F1=F2
100 F2=F
110 WEND
120 END

Generate Fibonacci series form 1,1,2,3,……upto Nth Term
10 LET F1=1
20 LET F2=1
30 LET F=0
40 INPUT “ENTER Nth TERM”;N
50 PRINT F1
60 PRINT F2
70 FOR I=3 TO N STEP 1
80 F=F1+F2
90 PRINT F
100 F1=F2
110 F2=F
120 NEXT I
130 END

Accept 10 elements in the array and display all the elements present in the array
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I=1 TO 10
60 PRINT A(I)
70 NEXT I
80 END

Accept 10 elements in the array and display only first five elements present in the array
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I=1 TO 5
60 PRINT A(I)
70 NEXT I
80 END

Accept 10 elements in the array and display only last five elements present in the array
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I=6 TO 10
60 PRINT A(I)
70 NEXT I
80 END

Accept 10 elements in the array and display the first three and last three elements present in the array
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I=1 TO 3
60 PRINT A(I)
70 NEXT I
80 FOR I=8 TO 10
90 PRINT A(I)
100 NEXT I

Accept 10 elements in the array and display the array in the reverse order as Inputted
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I=10 TO 1 STEP -1
60 PRINT A(I)
70 NEXT I
80 END

Accept 10 elements in the array and display the Alternate position of the array
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I=1 TO 10 STEP 2
60 PRINT A(I)
70 NEXT I
80 END

Accept 10 elements in the array and display the position of the odd elements present in the array
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I=1 TO 10
60 IF A(I) MOD 2=1 THEN PRINT I
70 NEXT I
80 END
 
Accept 10 elements in the array and COUNT the number of odd elements and the number of even elements present in the array
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I=1 TO 10
60 IF A(I) MOD 2=0 THEN C=C+1 ELSE D=D+1
70 NEXT I
80 PRINT "NUMBER OF EVEN NUMBERS";C
90 PRINT "NUMBER OF ODD NUMBERS";D
100 END
 
Accept 10 elements in the array and display the prime numbers present in the array
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I= 1 TO 10
60 C=0
70 FOR J= 1 TO A(I)
80 IF A(I) MOD J=0 THEN C=C+1
90 NEXT J
100 IF C=2 THEN PRINT A(I)
110 NEXT I
120 END

Accept 10 elements in the array and COUNT the number of prime numbers and composite number present in the array
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I= 1 TO 10
60 C=0
70 FOR J= 1 TO A(I)
80 IF A(I) MOD J=0 THEN C=C+1
90 NEXT J
100 IF C=2 THEN PRIME=PRIME+1 ELSE COMPOSITE=COMPOSITE+1
110 NEXT I
120 PRINT "NUMBER OF PRIME ";PRIME
130 PRINT "NUMBER OF COMPOSITE"; COMPOSITE
140 END

Accept 10 elements in the array REVERSE each number present in the array
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I= 1 TO 10
60 S=0
70 N=A(I)
80 WHILE N>0
90 J=N MOD 10
100 S=S*10 + J
110 N=INT(N/10)
120 WEND
130 PRINT S
140 NEXT I
150 END

Accept 10 elements in the array display all the palindromic number present in the array
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I= 1 TO 10
60 S=0
70 N=A(I)
80 WHILE N>0
90 J=N MOD 10
100 S=S*10 + J
110 N=INT(N/10)
120 WEND
130 IF S=A(I) THEN PRINT A(I)
140 NEXT I
150 END

Accept 10 elements in the array COUNT the palindromic number  and non palindromic number present in the array
10 DIM A(10)
20 FOR I= 1 TO 10
30 INPUT "ENTER ELEMENT";A(I)
40 NEXT I
50 FOR I= 1 TO 10
60 S=0
70 N=A(I)
80 WHILE N>0
90 J=N MOD 10
100 S=S*10 + J
110 N=INT(N/10)
120 WEND
130 IF S=A(I) THEN D=D+1 ELSE E=E+1
140 NEXT I
150 PRINT "NUMBER OF PALINDROMIC NUMBER";D
160 PRINT "NUMBER OF NON PALINDROMIC NUMBER";E
170 END 

Comments