Basic Programming 5th Sem
Basic Programming 5th Sem
DEGREE COLLEGE
LLE 3E
R,NORTH
DHARMANAGAR,
TRIPURA
PHYSICs DEPARTMENT
INDEX
PAGE
SL CONTENTS REMARKS
No. No.
INTRODUCTION 3 to 5
11
Write a program in BASIC to input two numbers and 15
calculate their H. C.F.
12
Write a program in BASICto input 10 numbers and 16
print the numbers at the output in ascending order.
EXAA
BASIC PROGRAMMING
SL PAGE
CONTENTS REMARKS
No. No.
13
Write a program in BASIC to input 10 numbers and 17
print the numbers at the output in descending order.
Write aprogram in BASIC to input 10 numbers and
14 arrange the number in reverse order in two columns at 18
the output.
Write a program in BASIC to print 10 Fibonacci 19
15
numbers at the output where T(1)=0and T(2)=1
16 Write a program in BASIC to input a temperature in 19
Celsius scale and convert it into Fahrenheit scale.
Write a program in BASIC to input a temperature in 20
17 Fahrenheit scale and convert it into a Celsius scale.
Write a program in BASIC to input radius of a sphere 20
18
incentimetre and caiculate its area and volume.
Write a program in BASC to input a five-digit number.
19
Construct a new number where the digits are arranged 21
in reverse order and print both five digits numbers as
output.
Write a program in BASIC to input the focal length of a
20 convex lens. If the object distance is given. Calculate 21
the image distance.
Write a program in BASIC to input a five digit number.
Construct a new number where the digits are arranged 22
21
in ascending and descending order and print both five
digit numbers as output.
22
Write a program in BASIC to input five resistance when 23
they are in parallel combination.
23
Write a program in BASIC to print first 10 terms of the 23
following series. 0,3, 8, 15,24,35..
24
Write a program in BASIC to input the numbers of days 24
and convert it into year, month and day.
Write aprograrn in BASIC tofind all three digit
25
numbers for which sum of the cube of the digits is 24
equal to the numbers itself
e.g.,153=13+5°+33 (Armstrong number)
Page |2
BASIC PROGRAMMING
INTRODUCTION
BASIC (an acronym for Beginner's All-purpose symbolic instruction Code) is family of
general purpose, high level programming languages whose design philosophy
emphasis ease of use.
In 1964, John G. Kemeny and Thomas E Kurtz designed the original Basic language
at Dartmouth College in new Hampshire. They wanted to enable students in fields
other than science and mathematics to use computers required writing custom
software,which was something only scientists and mathematicians tended to learn.
BASIC :Basic is a high level language. It was developed in 1964, itquickly becomes
one of the most popular language for general purpose use and scientific
applications.
Keyfeatures of BASIC:
> Commands
Program statements
> Data
Commands are executable instruction such as SAVE, LOAD, LIST etc. They are
generally executable in direct mode.
Page | 3
BASIC PROGRAMMING
Programming language :
called
function of a computer is controlled bya set of instructions
The to tell the computer,
computer program. These instructions are written
What operation to perform?
Where to locate the data?
Page | 4
BASIC PROGRAMMING
Commands Functions
running it to any new
After typing one program and before
NEW. By the command
program, one has to use the command
can be displayed on the
NEW
NEW, new line number 1,2,3.. .....
Screen of monitor.
the screen of the monitor.
CLS The command is used to clear
generate line number.
AUTO The command is used to automatically
the program
This command is used to list allor part of
LIST
currently in memory.
program file from disc into
This command is used to load a
LOAD
main memory.
of file from specified
This command is used to display the list
FILES
drive.
allows the user to
The full form is REMARK. This statement
ignore. It is a
REM type any information which the computer will
non-excitable command.
currently in
This command is used to excite the program
RUN
memory.
be store in
Using the command save the correct program can
SAVE
secondary storage.
The stop statement terminate the program execution before
STOP the end of the program unit.
This command is used to remember the program lines in RAM.
RENUM
GOTO This statement go to transfer the control to the line numbers.
This command is used to edit specified program line currently
EDIT
in memory.
It is the end state of a sub program and causes the transfer of
RETURN
control to the main program.
When a program is not required any more, one can erase the
KILL program from the disk using this command.
DELETE If wants to delete aprogram that is currently in memory.
GOSUB This statement transfer control to specified line number.
END It is last command of a program which terminates a program.
This command is used to exit from GW-BASIC and return the
SYSTEM
operating system.
Page | 5
BASIC PROGRAMMING
AFTER RUN
ENETR ANY THREE SIDES:5
??6
???4
TRIANGLE CAN BE FORMED
GREATEST SIDE IS=6
ENETR ANY THREE SIDES : 1
??5
???9
TRIANGLE CANNOT BE FORMED
ENETR ANY THREE SIDES :
Page 6
BASIC PROGRAMMING
AFTER RUN
ENTER THREE SIDES:3
??4
???5
TRIANGLE CAN BE FORMED
AREA OF THE TRIANGLE=6
ENTER THREE SIDES:1
??2
???3
TRIANGLE CANNOT BE FORMED
ENTER THREE SIDES:
Page 7
BASIC PROGRAMMING
AFTER RUN
ENTER THREE SIDES:3
??4
???5
TRIANGLE CAN BE FORMED
RIGHT ANGLE TRIANGLE CAN BE FORMED
ENTER THREE SIDES: 4
??5
???6
TRIANGLE CAN BE FORMED
RIGHT ANGLE TRIANGLE CANNOT BE FORMED
ENTER THREE SIDES:
Page | 8
BASIC PROGRAMMING
AFTER RUN
ENTER ANY INTEGER :0
EVERY INTEGER ARE DIVISOR OF ZERO
ENTER ANY INTEGER:8
DIVISORS OF 8 ARE
1
2
4
8
ENTER ANY INTEGER:7
DIVISORS OF7 ARE
1
7
ENTER ANY INTEGER:
Page | 9
BASIC PROGRAMMING
AFTER RUN
ENTER 10 RANDOM NUMBERS
?4
?5
?1
26
?3
?8
?5
?7
?9
22
2l04/es
Page | 10
BASIC PROGRAMMING
6. Write aprogram in BASIC to input 10
even numbers at the random numbers. Print all the
output.
1 CLS
2
3
PRINT"ENTER 10
FOR I=l TO 10 RANDOM NUMBERS"
4 INPUT A(I)
5 NEXT
6 PRINT""
7
8
PRINT"EVEN NUMBERS
FOR I=1 TO 10
ARE"
9 IF A (I) <>0 AND A (I)
MOD 2=0 THEN PRINT A (I)
10 NEXT
11 END
AFTER RUN
ENTER 10 RANDOM NUMBERS
?1
?4
?7
?2
?5
?8
?3
?6
?9
?6
Page | 11
BASIC PROGRAMMING
AFTER RUN
PRIME NUMBER FROM 1 TO 100
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
Page | 12
BASIC PROGRAMMING
AFTER RUN
ENETR 10 NATURAL NUMBERS
?64
?56
?52
?51
?23
?89
?23
?213
?657
?35
SUM=1263
Page | 13
BASIC PROGRAMMING
AFTER RUN
ENTER ANY NUMBER=3
FACTORIAL OF 3 IS : 6
ENTER ANY NUMBER=5
FACTORIAL OF 5 IS: 120
ENTER ANY NUMBER=
AFTER RUN
ENTER ANY TWO NUMBER=9
??6
L.C.M=18
Page | 14
BASIC PROGRAMMING
11. Write a program in BASIC to input two numbers and calculate thelr
H.C.E.
1 CLS
TNPUT"ENTER ANY TWO NUMBER=";A,B
3 M=A
4 N=B
5 WHILE A<>0
6 R=B MOD A
7 B=A
8 A=R
9 WEND
10 PRINT"H.C.F=";B
11 GOTO 2
12 END
AFTER RUN
ENTER ANY TWO NUMBER=5
??6
H.C.F=l
ENTER ANY TWO NUMBER=6
??8
H.C.F=2
ENTER ANY TWO NUMBER=
Page | 15
BASIC PROGRAMMING
AFTER RUN
ENTER ANY 10 NUMBERS
?21
?56
?453
?654
?21
?56
?6547
289
?1654
28912
ASCENDING ORDER IS
21
21
56
56
89
453
654
1654
6547
8912
Page | 16
BASIC PROGRAMMING
AFTERRUN
ENTER ANY 10 NUMBERS
?6
?54
?21
?65
?789
?3254
?6587
?2
?75
?562
DESCENDING ORDER IS
6587
3254
789
562
75
65
54
21
6
2
Page | 17
BASIC PROGRAMMING
14. Write a program in BASIC to
input 10 numbers and arrange the
number in reverse order in two columns at the
1 CLS output.
2
PRINT"ENTER ANY 10
3 FOR I=1 TO 10 NUMBER"
4 INPUT A(I)
5 NEXT
6 PRINT"REVERSE ORDER
7 FOR I=1 TO 10 ORIGINAL ORDER"
8 PRINT" ";A(1+10-I);"
9 NEXT ";A(I)
10 END
AFTER RUN
ENTER ANY 10 NUMBER
?213
?5
?65
?7
?98
?32
?0
?53
?21
?16
REVERSE ORDER ORIGINAL ORDER
16 213
21 5
53 65
7
32 98
98 32
7
65 53
5 21
213 16
Page 18
BASIC PROGRAMMING
AFTER RUN
T(1) =0
T(2) =1
T(1)=l
T(1)=2
T (1) =3
T(1) =5
T(1) =8
T(1)=13
T(1)=21
T (1) =34
AFTER RUN
ENTER TEMP IN CELCIUS : 32
TEMP IN FAHRENHEIT:89.6
Page | 19
BASIC PROGRAMMING
AFTER RUN
ENTER TEMP IN FAHRENHE IT:332
TEMP IN CELCIUS:
166.666667
AFTER RUN
THE RADIUS OF A SPHERE:7
AREA:615.44 VOLUME:1436.02667
Page | 20
BASIC PROGRAMMING
AFTER RUN
ENETR ANY 5 DIGIT NUMBERS: 65483
REVERSE ORDER SAME ORDER
38456 65483
AFTER RUN
ENTER FOCAL LENGTH, F=23
ENTER OBJECT DISTANCE, U =10
IMAGE DISTANCE, V=6.96969697
Page | 21
BASIC PROGRAMMING
AFTER RUN
ENTER FIVE DIGIT NUMBER: 4586
INVALID INPUT
ENTER FIVE DIGIT NUMBER:86952
ASCENDING ORDER
25689
DESCENDING ORDER
98652
Page | 22
BASIC PROGRAMMING
22. VWrite a program in BASIC to
parallel combination. input five resistance when they are in
1 CLS
2
PRINT"ENTER
3 FOR I=l TO 5
ANY FIVE
RESISTANCES"
4 INPUT A(I)
5 NEXT
6 LET P=0
7 FOR I=1 TO 5
8 P=(I/A(I)) +P
9 NEXT
10
PRINT"EQUIVALENT RESISTANCES, R="; 1/P
11 END
AFTER RUN
ENTER ANY FIVE
?6 RESISTANCES
?4
?9
?8
?2
EQUIVALENT RESISTANCES, R=0.25
AFTER RUN
0,3,8,15,24, 35, 48, 63, 80, 99,
Page | 23
BASIC PROGRAMMING
AFTER RUN
NUMBER OF DAYS:9845
26-YEARS 11-MONTHS 25-DAYS
25. Write a program in BASIC to find all three digit numbers for which
sum of the cube of the digits is equal to the numbers itself
e.g.,153=1'+5'+3° (Armstrong number)
1 CLS
2 FOR I=100 TO 999
3 S=0
4 A=I
5 P=I
6 WHILE A>0
7 R=A MOD 10
8 S=St+R^3
9 A=INT (A/10)
10 WEND
11 IF P=S THEN PRINT S
12 NEXT I
13 END
AFTER RUN
153
370
371
407
24|0|2
Page | 24