forked from dharmanshu1921/Daa-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRec.c
More file actions
65 lines (32 loc) · 956 Bytes
/
Rec.c
File metadata and controls
65 lines (32 loc) · 956 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
59
60
61
62
63
64
65
#include<stdio.h>
#define MAX 100
int MaxElem(int []);
int n;
int main()
{
int arr1[MAX],hstno,i;
printf("\n\n Recursion : Get the largest element of an array :\n"); printf("------------------------------------------------------\n");
printf(" Input the number of elements to be stored in the array :");
scanf("%d",&n);
printf(" Input %d elements in the array :\n",n);
for(i=0;i<n;i++)
{
printf(" element - %d : ",i);
scanf("%d",&arr1[i]);
}
hstno=MaxElem(arr1);//call the function MaxElem to return the largest element
printf(" Largest element of the array is: %d\n\n",hstno);
return 0;
}
int MaxElem(int arr1[])
{
static int i=0,hstno =-9999;
if(i < n)
{
if(hstno<arr1[i])
hstno=arr1[i];
i++;
MaxElem(arr1);//calling the function MaxElem itself to compare with further element
}
return hstno;
}