-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise2_of_function.cxx
62 lines (60 loc) · 1.27 KB
/
exercise2_of_function.cxx
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Write a program containing three functions, first function to read 6 elements of one
dimension array (called A), second function to sort array elements in ascending order
and store them in array B then print them, and the third function to sort array elements
in descending order and store them in array C then print them.
*/
#include <iostream>
#include <cstdio>
using namespace std;
int read (int[]);
int asc (int[],int[]);
int desc (int[],int[]);
int main(){
int A[6],B[6],C[6];
read (A);
asc (A,B);
for(int i=0;i<6;i++){
cout<<B[i];
}
cout<<endl;
desc (A,C);
for(int i=0;i<6;i++){
cout<<C[i];
}
}
int read (int D[]){
cout<<"Enter 6 Elements\n";
for(int i=0;i<6;i++){
cin>>D[i];
}
return D[6];
}
int asc (int A[6],int B[]){
int j;
for(int i=0;i<6;i++){
for(int k=i+1;k<6;k++){
if(A[i]>A[k])
j=A[i];
A[i]=A[k];
A[k]=j;
}
}
for(int i=0;i<6;i++){
B[i]=A[i];
}
}
int desc (int A[],int C[]){
int j;
for(int i=0;i<6;i++){
for(int k=i+1;k<6;k++){
if(A[i]<A[k])
j=A[i];
A[i]=A[k];
A[k]=j;
}
}
for(int i=0;i<6;i++){
C[i]=A[i];
}
}