-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray3.cpp
More file actions
43 lines (36 loc) · 815 Bytes
/
Array3.cpp
File metadata and controls
43 lines (36 loc) · 815 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
/*C++ Program that searches for the largest and smallest numbers in an array of known length and switches their indexes*/
#include <iostream>
using namespace std;
int main()
{
int n=0;
int numbers[6];
cout << "Enter numbers in array:\n";
while(n<6){
cin >> numbers[n];
++n;
}
n=1;
int maxn=numbers[0],minn=numbers[0];
int a=0,b=0;
while(n<6){
if(maxn<numbers[n]){
maxn=numbers[n];
a=n;
}else{}
if(minn>numbers[n]){
minn=numbers[n];
b=n;
}else{}
++n;
}
int temp=numbers[a];
numbers[a]=numbers[b];
numbers[b]=temp;
int i=0;
while(i<6){
cout <<"Number at index "<<i<<" "<<"is "<<numbers[i]<<endl;
++i;
}
return 0;
}