[go: up one dir, main page]

0% found this document useful (0 votes)
91 views12 pages

Pc-Basic Programs

The document provides instructions on editing lines in both new and saved GW-BASIC files, including how to delete characters, lines, and entire programs. It also includes practical programming examples for calculating areas, converting temperatures, and finding maximum numbers, among others. Additionally, it discusses the use of loops and conditional statements in GW-BASIC programming.

Uploaded by

shehreyar713
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)
91 views12 pages

Pc-Basic Programs

The document provides instructions on editing lines in both new and saved GW-BASIC files, including how to delete characters, lines, and entire programs. It also includes practical programming examples for calculating areas, converting temperatures, and finding maximum numbers, among others. Additionally, it discusses the use of loops and conditional statements in GW-BASIC programming.

Uploaded by

shehreyar713
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/ 12

Editing Lines in New Files

If an incorrect character is entered as a line is being typed, it can be deleted with


the BACKSPACE or DEL keys, or with CTRL-H. After the character is deleted, you can continue
to type on the line.
The ESC key lets you delete a line from the screen that is in the process of being typed. In
other words, if you have not pressed the RETURN key, and you wish to delete the current line
of entry, press the ESC key.
To delete the entire program currently residing in memory, enter the NEW command. NEW is
usually used to clear memory prior to entering a new program.

Editing Lines in Saved Files


After you have entered your GW-BASIC program and saved it, you may discover that you need
to make some changes. To make these modifications, use the LIST statement to display the
program lines that are affected:
1. Reload the program.
2. Type the LIST command, or press the F1 key.
3. Type the line number, or range of numbers, to be edited.
The lines will appear on your screen.

Editing the Information in a Program Line


You can make changes to the information in a line by positioning the cursor where the change
is to be made, and by doing one of the following:
• Typing over the characters that are already there.
• Deleting characters to the left of the cursor, using the BACKSPACE key.
• Deleting characters at the cursor position using the DEL key on the number pad.
• Inserting characters at the cursor position by pressing the INS key on the number pad.
This moves the characters following the cursor to the right making room for the new
information.
• Adding to or truncating characters at the end of the program line.
If you have changed more than one line, be sure to press RETURN on each modified line. The
modified lines will be stored in the proper numerical sequence, even if the lines are not
updated in numerical order.

Note
A program line will not actually have changes recorded within the GW-BASIC program until
the RETURN key is pressed with the cursor positioned somewhere on the edited line.

To delete a line, simply type the line number and press the RETURN key. For example, if you
type 12 and press the RETURN key, line number 12 is deleted from your program.
Rules for naming variables in GW-BASIC:
Relational Operators in BASIC: Suppose a, b, and c are three integer variables having values
123, 215 and 123 respectively then:
Program:How to build a program that input two numbers and add them and give result
10 cls
20 input"enter the first number to be add",x
30 input"enter the second number to be add",y
40 z=x+y
50 print x "+" y "=" z
60 end

program:How to build a program that calculate the area of circle and the formula is lets
consider pi=3.14 so Area=pi * Radius^2
10 input"enter the value of radius",r
20 pi=3.1415 (or you can use the constant value of pi in below expression)
30 area=pi * r^2 ( or you can use this formula i.e. area=3.1415*r*r)
40 print"the area of circle="area
50 end

program:How to build a program that calculate the area of triangle and formula is
Area=1/2*b*h
10 cls
20 input"enter the value of base=",x
30 input"enter the value of vertical height=",y
40 area=1/2*x*y
50 print"the area of triangle="area
60 end

program:How to build a program that calculate the area of square and formula is Area=a^2

10 cls
20 input"enter the length of any side of square",x
30 area=x*x
40 print"the area of square=" area
50 end
program:How to build a program that calculate the area cylinder formula is volume=pie*r^2*h

10 cls
20 input"enter the value of height of cylinder",x
30 input"enter the value of radius of cylinder",y
40 vol=3.14*y^2*x
50 print"the volume of cylinder="vol
60 end

Practical: Write a program that can calculate the area of the rectangle.

Practical: Write a program that can calculate the perimeter of the rectangular.

10 CLS

20 INPUT “Length …=”;L

30 INPUT “Width …=”; W

40 PERIMETER= 2* ( L+W)

50 PRINT “ PERIMETER….. =”; PERIMETER

60 END

Practical: Write a program that can calculate the square and cube of any number.

10 CLS

20 INPUT “ Enter any No..…=”; N

30 Sq = N*N

40 Cub= N^3

50 PRINT “ Square….. =”; Sq

60 PRINT “ Cube….. =”; Cub

70 END
Practical: Write a program that can convert temperature from Centigrade to Fahrenheit

10 CLS

20 INPUT “ Temperature in Centigrade :=”; C

30 F = 9/5* C+32

40 PRINT “Temperature in Fahrenheit =”; F

50 END

OR

Practical:14: Write a program that can convert temperature from Fahrenheit to Centigrade

10 CLS

20 INPUT “ Temperature in Fahrenheit :=”; F

30 C = 5/9* ( F-32)

40 PRINT “Temperature in Centigrade =”; C

50 END
Practical: 15: Write such program which can read or input four numbers from user and print
their average.
Program: How to build a program that calculate percentage of obtained numbers out of total
numbers in any exams.

10 cls
20 input"enter the total number",x
30 input"enter number you got",y
40 z=y/x
50 c=z*100
60 print"the percent="c
70 end

Practice:: write in pc-basic ( a Square + b Square + 2ab )

Sol:

10 let a = 2
20 let b = 3
30 let q1 = (a ^ 2) + (b ^ 2) + (2 * a * b)
40 print "Result of Q=a^2+b^2+2ab = ", q1
50 end

Program: write a program which can calculate the square of any number

SOL:

10 CLS
20 INPUT "Enter number:", n
30 s = n * n
40 PRINT "saquare of "; n; " is "; s
50 END
Program: Write a program to print the following pattern
*
***
*****

10 cls
20 new
30 rem
40 print "*"
50 print "***"
60 print "*****"
70 end

Program: How to use READ DATA in GW-Basic?

read the data from data and generate the output.


10 READ A,B
20 T=A+B
30 PRINT A;”+”;B;”=”;T
40 END
50 DATA 9,8

Practical: Write a program that can add 15+ 30+20+325 using READ and Data statement.

10 CLS

20 READ A,B,C,D

30 SUM= A+B+C+D

40 PRINT “SUM OF 15,30,20 AND 325 IS…=”; SUM

50 DATA 15,30,20,325

60 END
program: write a program to print numbers from 1 to 10 using goto statement

to set the conditions in the programme.


10 CLS
20 LET N = 0
30 LET N=N+1
40 PRINT N
50 IF N<10 THEN GOTO 30 ELSE GOTO 60
60 END
after executing the above programme computer will display 1 to 10 numbers in this way.

Program: Write a program to find maximum number out of two numbers?

10 CLS
20 INPUT "ENTER FIRST NUMBER: ",X

30 INPUT "ENTER SECOND NUMBER: ",Y


40 IF X > Y THEN PRINT " THE LARGEST NUMBER IS.",X ELSE PRINT " THE LARGEST NUMBER
IS.",Y

50 END

OR

10 CLS
20 INPUT "ENTER FIRST NUMBER: ",X

25 INPUT "ENTER SECOND NUMBER: ",Y


30 IF X > Y THEN GOTO 40 ELSE GOTO 50
40 PRINT " THE LARGEST NUMBER IS.",X : END
50 PRINT " THE LARGEST NUMBER IS.",Y
60 END

Program: Write a program to find number is even or odd?

10 CLS
20 INPUT "ENTER NUMBER: ",X
30 IF X MOD 2 = 0 THEN GOTO 40 ELSE GOTO 50
40 PRINT X " is even." :END
50 PRINT X " is odd."
60 END
Practical:: Write a program which can find the largest number of given three numbers.

Program: Find number is divisible by 7 or not.

10 CLS
20 INPUT "ENTER NUMBER: ",X
30 IF X MOD 7 = 0 THEN GOTO 40 ELSE GOTO 50
40 PRINT X " is divisible by 7." :END
50 PRINT X " is not divisible by 7."
60 END

Practical: program that can Print your name or a message five times using FOR-NEXT Loop.

10 CLS

20 FOR N =1 TO 5

30 PRINT “GOD IS GREAT”

40 NEXT N

50 END

Program:2: What is the use of FOR NEXT Loop in GW-Basic?

We use this loop to repeat the process to a specific time given in the loop.

5 REM Display from 1 to 5


10 FOR K = 1 TO 5
20 PRINT K
30 NEXT K
40 END
Program: How to use FOR NEXT with specific STEP?

2 CLS
5 REM odd number from 1 to 9 with for next
10 FOR K = 1 TO 10 STEP 2
20 PRINT K
30 NEXT K
40 END

Practical: Write a program that can print all even numbers from 2 to 100.

Program:

10 CLS

20 FOR B = 2 TO 100 STEP 2

30 PRINT B

40 NEXT B
50 END

program:How to build a program that show a table of any number

10 cls
20 input"enter the number whose table you wanted to see",x
30 for y=1 to 10
40 z=x*y
50 print x "*" y "=" z
60 next
70 end

OR
Practical: Write a program to show 1st ten odd numbers using while wend loop.

You might also like