Fundamentals of Programming Worksheet
Fundamentals of Programming Worksheet
Fundamentals of Programming Worksheet
For each of the problems write a C++ code to perform the required task. First you should do
flow chart for each question.
2) Obtain two numbers from the keyboard, and determine and display which (if either) is the larger
of the two numbers.
3) Receive 3 numbers and display them in ascending order from smallest to largest
5) Add the even numbers between 0 and any positive integer number given by the user.
7) Find the average, maximum, minimum, and sum of three numbers given by the user.
8) Find the area of a circle where the radius is provided by the user.
10) Swap the content of two variables without using a third variable.
11) Read an integer value from the keyboard and display a message indicating if this number is odd or
even.
12) read 10 integers from the keyboard in the range 0 - 100, and count how many of them are larger
than 50, and display this result
13) Obtain three integers from the user and display the maximum and the minimum using conditional
operator.
14) Write a program that displays LCM and GCF of the two integers. Note obtain the number from the
user.
15) Take an integer from the user and display the factorial of that number (draw only the flow chart).
16) Write for, do-while, and while statements to compute the following sums and products.
a. 1+2+3+…+100
b. 5+10+15+…+50
c. . 1+1/2+1/3+1/4+…1/15
d. 1*2*3*…*20
1
Fundamentals of programming Worksheet
17) A prime number is an integer greater than one and divisible only by itself and one. The first seven
prime numbers are 2, 3, 5, 7, 11, 13, and 17. Write a program that displays all the prime numbers
between 1 and 100.
18) Write a C++ program that counts the number of digits in an integer number. For example; 23,498
has five digits.
19) Write a C++ application that can compute the letter grade of a student after accepting the
student’s mid and final mark. The program should only accept mid result [0-40] and final [0- 60]. If
the data entered violates this rule, the program should display that the user should enter the mark
in the specified range. The program is also expected to run until the user refuses to continue. Note
use the following criteria to display the later grade :
if total mark>80 grade is A, if total mark>75 grade is B, if total mark>55 the grade is C, if total
mark>45 the grade is D and total mark<45 the grade is F.
20) Write a C++ program that accepts a positive number from the user and displays the factorial of
that number. Use for loops to find the factorial of the number.
21) Write a C++ program that accepts marks of five students and then displays their average. The
program should not accept mark which is less than 0 and mark greater than 100.
22) Write a C++ program using for loop that can compute the following summation:
23) Develop a calculator program that computes and displays the result of a single requested
operation.
E.g. if the input is
15 * 20, then the program should display 15 * 20 equals 300
If the operator is not legal, as in the following example
24 ~ 25 then the program displays ~ is unrecognized operator
As a final example, if the denominator for a division is 0, as in the following input: 23 / 0 then
the program should display the following:
23 / 0 can’t be computed: denominator is 0.