# 辅导Laboratory 程序、辅导program编程

Laboratory #2 Session 2-3

Topic:
Conditional statement
Loops

1.Write a C+ program to read a number n and to display the first n naturals numbers and their sum. Expected Output (for 10):
The first 10 natural number is:
1 2 3 4 5 6 7 8 9 10
The sum is: 55
2.Write a C++ program to read a number (integer) and to display its multiplication table
3.Write a C++ program to read a number (integer) and to compute if it is prime or not.
4.Write a C++ program to find prime number within a range.
5.Write a C++ program to read a number and to display a right angle triangle using an asterisk as following:

The number given by the user defines the number of row. (There is a space between each asterisk)
6.Write a C++ program to read a number and to display a right angle triangle using number as following:
1
1 2
1 2 3
1 2 3 4
The number given by the user defines the number of row. (There is a space between each number)
7.Write a C++ program to read a number and to display a right angle triangle using number as following:
1
2 2
3 3 3
4 4 4 4
The number given by the user defines the number of row. (There is a space between each number)
8.Write a C++ program to read a number and to display a pyramid using an asterisk as following:

The number given by the user defines the number of row. (There is a space between each asterisk)
9.Write a C++ program to read a number and to display a pyramid using an asterisk where each row contain and odd number of asterisks as following:

The number given by the user defines the number of row. (There is a space between each asterisk)
10.Write a C++ program to read a number and to display the triangle that have the following patern:
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
The number given by the user defines the number of row.
11.Write a C++ program to read a number and to display a pattern like a diamond. Each row contain and odd number.
12.Write a C++ program to read two numbers (integer) and to find greatest common divisor (GCD).
13.Write a C++ program to read a number n and to find all strong numbers within the range [1..n]. (As reminder, a strong number is a special number whose sum of the factorial of digites is equal to the original number. For exemple 145 is a strong number because 1! + 4! + 5! = 145.
14.Write a C++ program to read a number (integer) and to check if it is an Armstrong number. As reminder, an Armstrong number is a non-zero number which is equal to the sum of the pth powers of its digits in base ten, where p is the number of digits of n. For Example: 153 is an Armstrong number because 156 = 13 + 53 + 33.

Laboratory #3 Session 3-4

Topic:
Conditional statement
Loops
Arrays

You can use https://www.onlinegdb.com/online_c_compiler to complete these exercises. Use C++14 17 or 20.
15.Write a C++ program to read an array and to count a total number of duplicate elements .
16.Write a C++ program to read and to display all unique elements.
17.Write a C++ program to read an array and to display the frequency of each element. For example, for the array [7; 4; 9; 7]. It prints
7 occurs 2 times
4 occurs 1 times
9 occurs 1 times
18.Write a C++ program to read an array and to find the maximum and minimum elements.
19.Write a C++ program to read an array and to separate odd and even numbers in two separate arrays.
20.Write a C++ program to sort elements of an array in descending order.
21.Write a C++ program to delete an element at desired position from an array.
22.Write a C++ program to randomly generate two arrays and to count the total number in common.
23.Write a C++ program to convert a number into binay.
24.Write a C++ program to check if a given number n appears more then m/2 times in a sorted array of m integers
25.Write a C++ program to find majority element of an array.
26.Write a C++ program to check wheter an array is a subset of another array. For example, for given arrays tab1 [7; 9; 11; 0; 3; 20; 4] and tab2 [11; 7; 0; 3]. tab2 is a subarray of tab1