# Creating Programs on Visual Basic

Topics: Computer, For loop, Computer programming Pages: 13 (1323 words) Published: October 15, 2012
BASIC INPUT/OUTPUT:
1. Create programs and write the algorithms of the given problems: Write a program that computes the product of two numbers:
ALGORITHM:
ENTER two numbers
Compute the product of P=N1*N2
PRINT P
PROGRAM:
Program Product;
Uses crt;
Var N1,N2:integer;
Product:integer;
Begin
Clrscr;
Writeln(enter two numbers);
Product:=N1*N2;
Writeln(The product:product);
End.

2. Create a program that computes the difference of two numbers ALGORITHM:
ENTER TWO NUMBERS
Compute the difference
PRINT D
PROGRAM:
Program difference;
Uses crt;
Var N1,N2: integer;
Difference : integer;
Begin
Clrscr;
Writeln(enter the two numbers);
D:=N1-N2;
Writeln(‘the difference:difference’)
End.

3. Write a program that computes the sum of two
ALGORITHM:
ENTER TWO NUMBERS
Compute the difference
PRINT D
PROGRAM:
Program difference;
Uses crt;
Var N1,N2: integer;
Difference : integer;
Begin
Clrscr;
Writeln(enter the two numbers);
D:=N1-N2;
Writeln(‘the difference:difference’)
End.
1.

SHORT IF THEN ELSE:

2. Create a program that determines If the input age is qualified to vote or not. Qualifying age is 18, If not (else), print” too young!” Algorithm:
ENTER A
If A>=18 THEN
PRINT ”Qualified to VOTE”
ELSE
PRINT “TOO YOUNG”
PROGRAM:
Program vote;
Uses crt;
Var A:integer;
Begin
Clrscr;
If(A>=18)then
Writeln(qualified to vote)
Else
Writeln(too young);
End.

3. Create a program that determines if the input numbers is a magic number (143) which is equivalent to the magic word: “I LOVE YOU”, if it is equivalent, then display the message.”Right” otherwise display the message. ”Wrong”. Algorithm:

ENTER N
IF N=143 THEN
PRINT “I LOVE YOU”
ELSE
PRINT “WRONG”
PROGRAM:
Program MagicNumber;
Uses crt;
Var N:integer;
Begin
Clrscr;
If(N=143)then
Writeln(I LOVE YOU)
Else
Writeln(WRONG);
End.

4. Create a program that determines if the input grade is “Passed” or “Failed”. The passing grade is 75 and above. Displays “Passed” or “Failed” based on this condition. ALGORITHM:
ENTER G
IF G>=75 THEN
PRINT “PASSED”
ELSE
PRINT “FAILED”
PROGRAM:
Uses crt;
Var G:interger;
Begin
Clrscr;
If(G>=75) then
Writeln(PASSED)
Else
Writeln(FAILED);
End.

1. Create a program that, display the corresponding color of the given input letter. The corresponding letter of each color are given below: B or b| BLUE|
R or r| RED|
G or g| GREEN|
Y or y| YELLOW|
Other letters| Unlisted Color|

ALGORITHM:
ENTER L
IF L=B OR L=b THEN
WRITELN BLUE
ELSE IF L=R OR L=r THEN
WRITELN RED
ELSE IF L=G OR L=g THEN
WRITELN GREEN
ELSE IF L=Y OR L =y THEN
WRITELN YELLOW
ELSE
WRITELN Unlisted Color

PROGRAM:
Program Colo;
Uses crt;
Var L:char;
Begin
Clrscr;
If(L=B) or (L=b)then
Writeln(BLUE)
Else if(L=R) or (L=r)then
Writeln(RED)
Else if(L=G) or (L=g)then
Writeln(GREEN)
Else if(L=Y) or (L=y)then
Writeln(YELLOW)
Else
Writeln(Unlisted Color);
End.

2. Create a program that will display the corresponding college level of the given input year. The year and college level are given below: 1| FRESHMEN|
2| SOPHOMORE|
3| JUNIOR|
4| SENIOR|
Other Year| Unlisted Year-level|

ALGORITHM:
ENTER N
IF(N=1) THEN
WRITELN(FRESHMEN)
ELSE IF(N=2)THEN
WRITELN(SOPHOMORE)
ELSE IF(N=3)THEN
WRITELN(JUNIORS)
ELSE IF(N=4)THEN
WRITELN(SENIORS)
ELSE
WRITELN(Unlisted Year)

PROGRAM:
Program Collegelevel;
Uses crt;
Var N:integer;
Begin
Clrscr;
Writeln(enter a year);
If(N=1)then
Written(FRESHMEN)
Else if(N=2)then
Writeln(SOPHOMORE)
Else if(N=3)then
Writeln(JUNIORS)
Else If(n=4)then
Writeln(SENIORS)
Else...