-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ2.cpp
More file actions
42 lines (35 loc) · 1.05 KB
/
Q2.cpp
File metadata and controls
42 lines (35 loc) · 1.05 KB
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
// Array Operations
// Write a program that performs the following operations on an array:
// a. Accept an integer array from the user (size determined at runtime).
// b. Reverse the array and display it.
// c. Find and display the second largest and second smallest elements in the array.
#include <iostream>
using namespace std;
int main(){
int n,max,min,temp;
cout<<"Enter number of elements you want in array : ";
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cout<<"Enter elements of array : ";
cin>>arr[i];
}
cout<<endl;
cout<<"Reversed array : ";
for(int j=n-1;j>=0;j--){
cout<<arr[j]<<" ";
}
cout<<endl;
for(int k=0;k<n-1;k++){
for(int m=0;m<n-k-1;m++){
if(arr[m]>arr[m+1]){
temp=arr[m];
arr[m]=arr[m+1];
arr[m+1]=temp;
}
}
}
cout<<"The second largest number in the array is "<<arr[1]<<endl;
cout<<"The second smallest number in the array is "<<arr[n-2]<<endl;
return 0;
}