Você está na página 1de 1

Challenging Tasks 04 (Use C++ for these tasks)

1. Write a program that uses while statement to sum a sequence of integers. Assume that the first
integer read specifies the number of values remaining to be entered. Your program should read only
one value per input statement. A typical input sequence might be [5 100 200 300 400 500],
where the 5 indicates that the subsequent 5 values are to be summed.
2. Write a program that uses while statement to calculate and print the average of several integers.
Assume the last value read is the sentinel 9999. A typical input sequence might be [10 8 11 7 9
9999], indicating that the program should calculate the average of all the values preceding 9999.
3. Read 4 values from user (Give message to give number in range 5-20). Using loop print Stars in 4
different columns according to the value entered by user. You should print Stars in a way all starts
have base to down, means from bottom of screen they should be equal; however; they may vary on
top like:

*
* *
* * *
* * * *
* * * *
* * * *
4. A mail order house sells five different products whose retail prices are: product 1 $2.98, product
2$4.50, product 3$9.98, product 4$4.49 and product 5$6.87. Write a program that reads a series of
pairs of numbers as follows:
a. product number
b. quantity sold
Your program should use if statement to determine the retail price for each product. Your program
should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop
to determine when the program should stop looping and display the final results.
Note: By sentinel control means give some value as termination & put while condition according to
that value.
5. Write a program that prints a table of the binary, octal and hexadecimal equivalents of the decimal
numbers in the range 30 through 60. You have read these conversions in ITC course.
6. Calculate the value of from the infinite series. Print a table that shows the approximate value of
after each of the first 1,000 terms of this series. Formula is given. Here you can run while loop on
value of k and might set any value of n>=10000
(1)+1
Note: Use formula = 4 =1 21

7. (Pythagorean Triples) A right triangle can have sides that are all integers. A set of three integer
values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy
the relationship that the sum of the squares of two of the sides is equal to the square of the
hypotenuse. Find all Pythagorean triples for side1, side2 and hypotenuse all no larger than 500.
Use a triple-nested for loop that tries all possibilities. This is an example of brute force computing.
You will learn in more advanced computer-science courses that there are many interesting problems
for which there is no known algorithmic approach other than sheer brute force.
Note: Don't confuse this is interesting problem for triple nested loop, the idea is run 3 loops on
variables i, j & k (of course nested with each running from 1 to 500 & test is the square sum of first 2
loop variables is equal to the square sum of 3rd loop variable, if satisfy print i, j & k.

Você também pode gostar