Sunday, October 13, 2013

List of BASIC programs for beginners to get help

Welcome to my Blog. I have created this blog for beginner students who are studying BASIC programming language. BASIC:
             BASIC stands for Beginners All purpose Symbolic Instruction Code. BASIC is a high level programming language. As its name shows, it is designed especially for beginners. BASIC was developed in 1964 by John Kemeny and Thomas Kurtz at Darmouth College in New Hampshire. It is very important and useful for beginners who are in programming field. BASIC is also useful for some high-ended programming. 

GW-BASIC:
            GW-BASIC Stands for General Work Beginners All purpose Symbolic Instruction Code. It is an Interpreter (Language Translator) for BASIC language. GW-BASIC is one of the most solid and popular Interpreter for BASIC language. It was developed my Microsoft in 1983.

Programs of BASIC Language:



1. A program to print sum two numbers:


Syntax:
10 CLS
20 A=6
30 B=7
40 Sum=A+B
50 Print"Sum =";Sum
60 End
Screenshot in GW-BASIC














Execution:

SUM=14
Screenshot in GW-BASIC







                                 









2. A program that prints sum of two numbers after getting them from the user:

Syntax:
10 cls
20 input"Enter the first number";a
30 input"Enter the second number";b
40 s=a+b
50 print"Sum of two numbers=";s
60 end
Syntax in GW-BASIC















Execution:

Enter the first number? 55
Enter the second number? 29
Sum of two numbers= 84
Execution in GW-BASIC


















3. A program to print product of two numbers:

Syntax:

10. CLS
20 A=4
30 B=8
40 P=A*B
50 Print"Product of two numbers=";P
60 End




Execution:

Product of two numbers= 32



4. A program to print product of two numbers after getting them from the user:

Syntax:

10 cls
20 Input"Enter the first number";a
30 Input"Enter the second number";b
40 p=a*b
50 Print"Product of two numbers=";p
60 END



Execution:

Enter the first number? 5
Enter the second number? 4
Product of the two numbers= 20


5. A program to divide first number by the second number :

Syntax:
10 CLS
20 A=16
30 B=4
40 D=A/B
50 print A;"/;"B;"=";D
60 End



Execution:
16/4=4


6. A program to get two numbers by the user and then divide the first number by the second one:

Syntax:
10 CLS
20 INPUT"ENTER THE FIRST NUMBER";A
30 INPUT "ENTER THE SECOND NUMBER:'B
40 C=A/B
50 PRINT A;"/";B;"=";C
60 END


Eexecution:
ENTER THE FIRST NUMBER? 64
ENTER THE SECOND NUMBER? 8
8/64=8



7. A program to subtract two numbers:

Syntax:

10 CLS
20 A=6
30 B=2
40 C=A-B
50 PRINT A;"-";B;"=";C
60 END




Execution:
6-2=4



8. A program which gets two numbers from the user and then subtracts one from other:

Syntax:
10 CLS
20 INPUT"ENTER THE FIRST NUMBER";A
30 INPUT"ENTER THE SECOND NUMBER";B
40 S=A-B
50 PRINT A;"-";B;"=";S
60 END




Execution:
ENTER THE FIRST NUMBER? 55
ENTER THE SECOND NUMBER? 5
55-5=50


9. A program that tells the greater number between two numbers:

Syntax:
10 CLS
20 A=60
30 B=58
40 IF A>B THEN PRINT A;"IS GREATER THAN";B:END
50 PRINT B;"IS GREATER THAN";A
60 END



Execution:
60 IS GREATER THAN 58



10. A program that gets two numbers from the user and then tells the greater one:

Syntax:
10 CLS
20 INPUT"ENTER THE FIRST NUMBER";A
30 INPUT"ENTER THE SECOND NUMBER";B
40 IF A>B THEN PRINT A;"IS GREATER THAN";B:END
50 PRINT B;"IS GREATER THAN";A
60 END



Execution:
ENTER THE FIRST NUMBER? 4
ENTER THE SECOND NUMBER? 9
9 IS GREATER THAN 4


11. A program that tells the smaller number between two numbers:

Syntax:
10 CLS
20 A=9
30 B=8
40 IF A
50 PRINT B;"IS LESS THAN";A
60 END



Execution:
8 IS SMALLER THAN 9



12. A program that gets two numbers from the user and then tells the smaller one:

Syntax:
10 CLS
20 INPUT"ENTER THE FIRST NUMBER";A
30 INPUT"ENTER THE SECOND NUMBER";B
40 IF A
50 PRINT B;"IS LESS THAN";A
60 END



Execution:
ENTER THE FIRST NUMBER? 79
ENTER THE SECOND NUMBER? 56
56 IS SMALLER THAN 79



13. A program that tells the greater number between three numbers:

Syntax:
10 CLS
20 A=78
30 B=33
40 C=35
50 IF A>B THEN GOTO 60 ELSE GOTO 70
60 IF B>C THEN PRINT A;"IS THE GREATEST ONE":END ELSE PRINT C;"IS THE GREATEST ONE":END
70 IF A>C THEN PRINT B;"IS THE GREATEST ONE":END ELSE PRINT C;"IS THE GREATEST ONE"
80 END


Execution:
78 IS THE GREATEST ONE



14. A program that gets three numbers from the user and then tells the greatest one:

Syntax:
10 CLS
20 INPUT"ENTER THE FIRST NUMBER";A
30 INPUT"ENTER THE SECOND NUMBER";B
40 INPUT"ENTER THE THIRD NUMBER";C
50 IF A>B THEN GOTO 60 ELSE GOTO 70
60 IF B>C THEN PRINT A;"IS THE GREATEST ONE":END ELSE PRINT C;"IS THE GREATEST ONE":END
70 IF A>C THEN PRINT B;"IS THE GREATEST ONE":END ELSE PRINT C;"IS THE GREATEST ONE"
80 END



Execution:
ENTER THE FIRST NUMBER? 9
ENTER THE SECOND NUMBER 56
ENTER THE THIRD NUMBER 34
56 IS THE GREATEST NUMBER



15. A program that tells whether a given number is even or odd

Syntax:
10 CLS
20 INPUT"ENTER THE NUMBER";A
30 IF A MOD 2=0 THEN GOTO 40 ELSE GOTO 50
40 PRINT A;"IS EVEN NUMBER":END
50 PRINT A;"IS ODD NUMBER"
60 END




16. A program which gets an alphabet from user and then tells whether it is a vowel or a consonant:

Syntax:
10 CLS
20 INPUT"PLEASE ENTER THE ALPHABET";A$
30 IF A$="A" THEN PRINT"VOWEL":END
40 IF A$="E" THEN PRINT"VOWEL":END
50 IF A$="I" THEN PRINT"VOWEL":END
60 IF A$="O" THEN PRINT"VOWEL":END
70 IF A$="U" THEN PRINT"VOWEL":END
80 PRINT"CONSONENT"
90 END



Execution:
PLEASE ENTER THE ALPHABET? U
VOWEL



17. A program which gets the marks of all the subjects of the student and then gets the total marks and then shows obtained marks, percentage and grade according to the Sargodha board:

10 CLS
20 INPUT"ENTER YOUR NAME";A$
30 PRINT
31  INPUT"IF YOU ARE BIO STUDENT ENTER 1 AND FOR COMPUTER ENTER 2",N
40 INPUT"ENTER YOUR MARKS IN MATHEMATICS";A
41 INPUT"ENTER YOUR MARKS IN PHYSICS";B
42 INPUT"ENTER YOUR MARKS IN ENGLISH";C
43 INPUT"ENTER YOUR MARKS IN URDU";D
44 INPUT"ENTER YOUR MARKS IN CHEMISTRY";E
45 INPUT"ENTER YOUR MARKS IN PAK. STUDIES";F
46 INPUT"ENTER YOUR MARKS IN ISLAMIAT";G
47 ON N GOTO 48,49
48 INPUT"ENTER YOUR MARKS IN BIOLOGY";H
49 INPUT"ENTER YOUR MARKS IN COMPUTER";I
50 S=A+B+C+D+E+F+G+H+I
60 PRINT
70 INPUT"ENTER TOTAL MARKS";O
80 J=S*100/O
90 PRINT A$;"YOUR TOTAL MARKS ARE";S
100 PRINT
110 PRINT"YOUR %ge IS ";J;"%"
120 END


18. A Program which gets a number from user and then prints the square root of that number.

Syntax:
10 cls
20 input"Enter the Number";a
30 print"Square root of";a;"=";sqr(a)"
40 end