Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

EXERCISES OF FUNDAMENTAL OF PROGRAMMING (PART 1)

1. Use iteration to sum S of the first eleven terms S = 100+105+110+115+….


2. Enter a real number A from the keyboard. Find the smallest natural number N such that:
1+1/2 + 1/3 +….+1/N > A.
 1 1 1
3. Find the number , knowing that: = 1- + - +….
4 3 5 7
1
With precision | | < 10-5
2n  1
4. Given an array A(i) (i=1,N). Write a program:
a. Calculate and print the average of all positive numbers.
b. Count and print how many numbers are divisible by 3.
c. Print the position of zeros (if any) in the given array.
5. Write a program to find all 3-digit numbers whose sum of the cubes of its digits is equal to the number
itself (Armstrong Numbers).
6. Enter a real number and calculate:
x x 2 x3 xn xn
S = 1+ + + +…. with precision | | < 10-5.
1! 2! 3! n! n!
7. Enter a real number x from keyboard and calculate:
x 2 x 4 x6 x 2n x 2n
S= 1+ + + + …. + Until | | < 10-5.
2! 4! 6! (2n)! (2n)!
8. Given any array of integers large enough (including 1/3 of elements less than 0, 1/3 of elements is 0,
1/3 of positive elements). Write a program to sum the 5 smallest positive numbers in the given array.
9. The conditions are the same as in Exercise 8. But it is required to write a program to calculate the
sum of the 5 largest negative numbers in the given array.
10. Given two arrays of numbers a1, a2, … an and b1, b2, …., bm . Write a program to build and print a
new array from the above two ranges in ascending order.
11. The Fibonacci sequence is defined as follows: a1= a2=1; an= an-1 + an-2 for n  2. Let's:
a. Enter a number n and print the first n Fibonacci numbers.
b. Enter a number n and print out the Fibonacci numbers  n.
12. Enter 4 numbers a, b, c, d, respectively. Find the largest number and its position.
13. Enter 4 numbers a, b, c, d, respectively. Find the smallest number and its position.
14. Enter two integers a, b. Find the greatest common divisor of (a,b).
15. Given a base 10 integer. Write a program:
a. Convert that integer to base two, base eight, base sixteen, base n.
b. Print the literal interpretation of the integer.

PHẠM MINH HOÀN PhD – SCHOOL OF INFORMATION TECHNOLOGY AND DIGITAL ECONOMIC
(hoanpm@neu.edu.vn)

You might also like