-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_HW1.cpp
More file actions
58 lines (42 loc) · 762 Bytes
/
3_HW1.cpp
File metadata and controls
58 lines (42 loc) · 762 Bytes
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
#include <iostream>
using namespace std;
int* makeArray(const int n);
void printArray(const int* arr, const int n);
int sumArray(const int n);
int main()
{
int n;
cout << "Enter Arrary size : " ;
cin >> n;
int* arr = makeArray(n) ;
printArray(arr, n);
int sum = sumArray(n);
cout << "\nSum of the array : " << sum;
delete[] arr;
return 0;
}
int* makeArray(const int n)
{
int* arr = new int[n];
for (int i = 0; i < n; i++)
{
arr[i] = i + 1;
}
return arr;
}
void printArray(const int*arr, const int n)
{
for (int i = 0; i < n; i++)
{
cout << arr[i] << ' ';
}
}
int sumArray(const int n)
{
int sum = 0;
for (int i = 0; i < n; i++)
{
sum += i+1;
}
return sum;
}