-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex06.cpp
61 lines (51 loc) · 1.34 KB
/
ex06.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
57
58
59
60
61
#include <iostream>
const int ArSize = 5;
int fillArray(double values[], int ArSize);
void showArray(double values[], int size);
void reverseArray(double values[], int size);
int main()
{
double values[ArSize];
std::cout << "Fill array" << std::endl;
int size = fillArray(values, ArSize);
showArray(values, size);
std::cout << "Reverse array" << std::endl;
reverseArray(values, size);
showArray(values, size);
std::cout << "Reverse array except first and last element" << std::endl;
reverseArray(values + 1, size - 2);
showArray(values, size);
return 0;
}
int fillArray(double values[], int ArSize)
{
std::cout << "\nEnter a series of numbers (q to quit)" << std::endl;
int i=0;
for (i=0; i<ArSize; i++)
{
std::cout << "Enter number #" << i + 1 << ": ";
std::cin >> values[i];
if (!std::cin)
{
std::cin.clear();
std::cout << "Ending input.\n";
break;
}
}
return i;
}
void showArray(double values[], int size)
{
for (int i=0; i<size; i++)
{
std::cout << i+1 << ":" << values[i] << std::endl;
}
}
void reverseArray(double values[], int size)
{
double temp[ArSize];
for (int i=0; i<size; i++)
temp[size - (i+1)] = values[i];
for (int i=0; i<size; i++)
values[i] = temp[i];
}