-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecur_15.cpp
62 lines (58 loc) · 1.25 KB
/
recur_15.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
62
#include <iostream>
int input(int[], int);
void display(int[], int);
int largestelem(int[], int);
int largecalc(int , int [], int , int ) ;
using namespace std;
int main()
{
int m;
cout << "Enter the size of the array: ";
cin >> m;
int a[m];
int size = sizeof(a) / sizeof(a[0]);
cout << "Enter the elements of Matrix: " << endl;
input(a, size);
cout << "Displaying the Matrix: " << endl;
display(a, size);
cout << "Largest element in the Array is:" << endl;
cout << largestelem(a, size);
return 0;
}
int input(int a[], int size)
{
for (int i = 0; i < size; i++)
{
cout << "a[" << i << "] = ";
cin >> a[i];
}
cout << endl;
return a[size];
}
void display(int a[], int size)
{
cout << "[";
for (int i = 0; i < size; i++)
{
cout << a[i] << " ";
}
cout << "]";
cout << endl;
}
int largecalc(int i, int arr[],int large, int size)
{
if (i == size)
{
return large;
}
if (arr[i] > large)
{
large = arr[i];
}
largecalc(i + 1, arr, large, size);
}
int largestelem(int arr[], int size)
{
int largest = arr[0];
return largecalc(0, arr, largest, size-1);
}