forked from MukulCode/CodingClubIndia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ2_SecondMaxSecondMin.c
More file actions
45 lines (45 loc) · 960 Bytes
/
Q2_SecondMaxSecondMin.c
File metadata and controls
45 lines (45 loc) · 960 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
// Himanshu Mohanty
// 2105719
// CSE36
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, max, min;
int secMax, secMin;
printf("Enter the number of element in the array:");
scanf("%d", &n);
int *ptr = (int *)malloc(n * sizeof(int));
printf("Enter the element of array\n");
for (int i = 0; i < n; i++)
{
scanf("%d", &ptr[i]);
}
max = ptr[0];
secMax = ptr[0];
for (int i = 0; i < n; i++)
{
if (ptr[i] > max)
{
secMax = max;
max = ptr[i];
}
else if (ptr[i] > secMax)
{
secMax = ptr[i];
}
}
min = ptr[0];
secMin = ptr[1];
for (int i = 0; i < n; i++)
{
if (ptr[i] < min)
{
secMin = min;
min = ptr[i];
}
}
printf("\nSecMax:%d\n", secMax);
printf("\nSecMin:%d\n", secMin);
return 0;
}