-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchetvurta_zadacha.cpp
56 lines (45 loc) · 1.35 KB
/
chetvurta_zadacha.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <math.h>
using namespace std;
double greaterThanZero(int point, int pointMinusOne, int pointPlusOne) {
return (((pow(pointMinusOne, 2) ) - (point * 2) + (pow(pointPlusOne, 2))) / (pointMinusOne - pointPlusOne));
}
double lessThanZero(int point, int pointMinusOne, int pointPlusOne) {
return (((pow(pointMinusOne, 2) ) - (point * 2) + (pow(pointPlusOne, 2))) / (pointPlusOne - pointMinusOne));
}
int main()
{
int size, point;
while (true)
{
cout << "Enter number of points in vector A: ";
cin >> size;
if (size <= 50)
break;
else
{
cin.clear();
cout << "Invalid input! Number must be equal or less than 50 " << endl;
}
}
double vectorB[size];
for (int i = 0; i < size; i++)
{
cout << "Enter point: ";
cin >> point;
int pointMinusOne = (point - 1);
int pointPlusOne = (point + 1);
if (point > 0)
vectorB[i] = greaterThanZero(point, pointMinusOne, pointPlusOne);
else if (point == 0)
vectorB[i] = 0;
else if (point < 0)
vectorB[i] = lessThanZero(point, pointMinusOne, pointPlusOne);
}
cout << "Vector B points are: " << endl;
for (int j = 0; j < size; j++)
{
cout << vectorB[j] << " ";
}
return 0;
}