Using three dimensional array, create a program that will enter table, row, and column together with the total number of Elements then display the Biggest number, Smallest number, and Second to the biggest number.
Sample input and output:
Input:
Enter number of Tables: 2
Enter number of Rows: 2
Enter number of Columns: 2
Enter 8 number of Elements
2
6
34
76
34
98
56
45
The biggest number among them is: 98
The smallest number among them is: 2
The second to the biggest number is: 76
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int table, rows, colums, i, j;
cout << "Enter number of Table: ";
cin >> table;
cout << "Enter number of Rows: ";
cin >> rows;
cout << "Enter number of Colums: ";
cin >> colums;
int size = table * rows * colums;
int arr[size];
int n = sizeof(arr) / sizeof(arr[0]);
cout << "Enter " << size << " number of Elements " << endl;
for (i = 0; i < size; i++){
cin >> arr[i];
}
for (i = 0; i < n - 1; i++)
for (j = 0; j < n - i - 1; j++)
if (arr[j] > arr[j + 1])
swap(arr[j], arr[j + 1]);
cout << "The biggest number among them is: " << arr[size-1] << endl;
cout << "The smallest number among them is: " << arr[0]<< endl;
cout << "The second to the biggest number is: " << arr[size-2]<< endl;
return 0;
}
Comments
Leave a comment