Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define MAX 100
- //nhập mảng 1 chiều
- void Input(int a[MAX],int n)
- {
- for(int i=0;i<n;i++)
- {
- cout<<"a["<<i<<"]:";
- cin>>a[i];
- }
- }
- //xuất mảng 1 chiều
- void Output(int a[MAX],int n)
- {
- for(int i=0;i<n;i++)
- {
- cout<<a[i]<<"\t";
- }
- }
- //sắp xếp tăng dần
- int sort(int a[MAX],int n)
- {
- if(n==1){
- return a[n-1];
- }
- else{
- sort(a,n-1);
- if(a[n-1] > a[n-2])
- {
- int temp=a[n-1];
- a[n-1]=a[n-2];
- a[n-2]=temp;
- sort(a,n-1);
- }
- }
- }
- //lấy 3 phần tử lớn nhất
- void max3(int a[MAX],int b[3],int n)
- {
- for(int i=0;i<3;i++)
- {
- b[i]=a[i];
- cout<<b[i]<<"\t";
- }
- }
- int main()
- {
- int n;
- int a[MAX],b[3];
- cout<<"Nhap so luong phan tu: ";
- cin>>n;
- Input(a,n);
- sort(a,n);
- max3(a,b,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement