1#include <stdio.h>
2int main() {
3 int i, n;
4 float arr[100];
5 printf("Enter the number of elements (1 to 100): ");
6 scanf("%d", &n);
7
8 for (i = 0; i < n; ++i) {
9 printf("Enter number%d: ", i + 1);
10 scanf("%f", &arr[i]);
11 }
12
13 // storing the largest number to arr[0]
14 for (i = 1; i < n; ++i) {
15 if (arr[0] < arr[i])
16 arr[0] = arr[i];
17 }
18
19 printf("Largest element = %.2f", arr[0]);
20
21 return 0;
22}
23
1#include <iostream>
2int main()
3{
4 std::cout << "Enter 5 numbers : ";
5 int arr[5];
6
7 for (int i = 0; i < 5; std::cin >> arr[i++]);
8
9 int max = arr[0], second = 0;
10
11 for (int i = 1; i < 5; i++)
12 if (arr[i] > max)
13 max = arr[i];
14 std::cout << "Maximum number : " << max << "\n";
15 bool found = false;
16 for (int i = 0; i < 5; i++)
17 {
18 if (arr[i] == max)
19 continue;
20 else if (arr[i] > second)
21 {
22 second = arr[i];
23 found = true;
24 }
25 }
26 if (found)
27 std::cout << "Second maximum numbers : " << second;
28 else
29 std::cout << "Second maximum number not found.";
30}