Upload
roy-collins
View
219
Download
1
Embed Size (px)
Citation preview
Writing Program Code in BASICWriting Program Code in BASIC
Write a program to Write a program to promptprompt for and for and acceptaccept values into TWO variables, numx and values into TWO variables, numx and numy. The program should numy. The program should squaresquare the the value stored in numx than value stored in numx than interchangeinterchange the values in TWO variables and the values in TWO variables and printprint these values.these values.
Writing Program Code in BASICWriting Program Code in BASIC
Check YOUR understanding.Check YOUR understanding.
Write a program which prompts the user Write a program which prompts the user to enter the price of an item and which to enter the price of an item and which calculates and prints the new price after calculates and prints the new price after a discount of 12%. a discount of 12%.
Writing Program Code in BASICWriting Program Code in BASIC
Whilst you’re in the mood …Whilst you’re in the mood …
Write a program to accept the radius of aWrite a program to accept the radius of a
circle, r, and compute and print its circle, r, and compute and print its
circumference based on the formula: 2πr. circumference based on the formula: 2πr.
The value of π is 3.142The value of π is 3.142
Writing Program Code in BASICWriting Program Code in BASIC
Write a program to Write a program to readread in TWO integers in TWO integers into variables A and B. into variables A and B. PrintPrint these these values. The program should values. The program should storestore the the smaller in A and the larger in B, and then smaller in A and the larger in B, and then printprint A and B. A and B. PrintPrint the value obtained by the value obtained by dividing the LARGER number by the dividing the LARGER number by the SMALLER number. You may assume SMALLER number. You may assume that the numbers are not equal.that the numbers are not equal.
Writing Program Code in BASICWriting Program Code in BASIC
Write a structured algorithm to accept Write a structured algorithm to accept values in TWO variables A & B. Print the values in TWO variables A & B. Print the product of these two variables if it is product of these two variables if it is greater than or equal to 100, otherwise greater than or equal to 100, otherwise print “SORRY – not enough”print “SORRY – not enough”
Writing Program Code in BASICWriting Program Code in BASIC
Check YOUR understanding.Check YOUR understanding.
Write a program in BASIC to read in the values Write a program in BASIC to read in the values of two numbers, find their sum, then their of two numbers, find their sum, then their product. Check whether the product is bigger product. Check whether the product is bigger than the sum. If the product is bigger, it must than the sum. If the product is bigger, it must print a message to say so, and if the product is print a message to say so, and if the product is not bigger it must print a message saying that not bigger it must print a message saying that the product is not bigger.the product is not bigger.
© CXC – June 2003© CXC – June 2003
Writing Program Code in BASICWriting Program Code in BASICUsing Using COUNT-CONTROLLED LOOPSCOUNT-CONTROLLED LOOPS
Write a program in BASIC to print the 2 Write a program in BASIC to print the 2
times multiplication table. Table should have times multiplication table. Table should have
the format:the format:2 x 1 = 22 x 1 = 2
2 x 2 = 42 x 2 = 4
..
..
2 x 12 = 242 x 12 = 24
Writing Program Code in BASICWriting Program Code in BASICUsing Using COUNT-CONTROLLED LOOPSCOUNT-CONTROLLED LOOPS
Write a program using BASIC to find the Write a program using BASIC to find the
sum of M numbers where the user supplies sum of M numbers where the user supplies
the value of M and types the numbers, in the value of M and types the numbers, in
response to the prompts generated by the response to the prompts generated by the
program.program.
Writing Program Code in BASICWriting Program Code in BASICUsing Using COUNT-CONTROLLED LOOPSCOUNT-CONTROLLED LOOPS
Try this one.Try this one.Write a program in BASIC to do the following:Write a program in BASIC to do the following:i.i. Announce (with a printed statement) that it will find the Announce (with a printed statement) that it will find the
volumes of sets of boxesvolumes of sets of boxesii.ii. Ask how many boxes there areAsk how many boxes there areiii.iii. For EACH box, ask for the length, width, and heightFor EACH box, ask for the length, width, and heightiv.iv. Compute the volume of EACH box. If the values of Compute the volume of EACH box. If the values of
length, width and height are all greater than zero, then length, width and height are all greater than zero, then print the volume.print the volume.
v.v. When finished with all the boxes, print the message: When finished with all the boxes, print the message: “Volumes have been found”.“Volumes have been found”.
Writing Program Code in BASICWriting Program Code in BASICUsing Using CONDITION-CONTROLLED LOOPSCONDITION-CONTROLLED LOOPS
Write a program in BASIC to accept and Write a program in BASIC to accept and
print a positive integer.print a positive integer.
Writing Program Code in BASICWriting Program Code in BASIC
Write a program to read a positive Write a program to read a positive integer N and find the average of all even integer N and find the average of all even numbers between 1 and N inclusive. numbers between 1 and N inclusive. Perform any necessary validation.Perform any necessary validation.