Assignment 1
Assignment 1
Laboratory work Nr 1
For course “PROGRAMMING”
The theme: Linear programs and math functions
Riga
2022 y.
1. Tasks for laboratory work
1) A user enters size of array: n (integer, positive).
2) Declare an one-dimensional dynamic array of integers of size n.
3) Implement filling the array by the user.
4) Display array values to the screen.
5) Calculate the sum of the positive elements of the array located between the
minimum and maximum elements (use the developed algorithm in the first
task).
6) Display the calculated sum to the screen
Calculate the average value of the array elements located after the first
negative element. The number of elements in the array is n. Array is the input
data to the algorithms.
Input: n, Array Output: Average
Individual task
Nr. 14
−√x + y 1
2 2
z= ∙
( 2 x +3 y ) √ 2
2
2. Algorithm
Figure 1 shows an algorithm for solving the problem in the form of a block diagram
х and y - input data, numeric value of double
type
z - output data, numeric value of double type
Fig.1. Algorithm
3. Source code
#include<iostream>
using namespace std;
int main()
{
float x, y;
cout << "Enter x> "; cin >> x;
cout << "Enter y> "; cin >> y;
float z = -(sqrt(x*x + y*y)) / pow((2 * x + 3 * y), 2)*(1 / sqrt(2));
cout << "z=" << z << endl;
2
system("PAUSE");
return 0;
}
4. Testing
Table 1 shows the results of testing the program
Table 1.
Program testing results
N Input data Output data
r x y Expected Received
1 0 0 No decision -1#IND
2 1 1 -0.04 -0.04
3 -1 -1 -0.04 -0.04
4 0.5 -0.123 -0.914439 -0.914439
5 -143.6 0.1 -0.00123361 -0.00123361
6. Conclusions