Untitled
raw download clone
CPP
views 21
,
size 1749 b
#include <iostream>
#include <list>
#include <iostream>
#include <sstream>

using namespace std;

void swap(int *a , int *b)
{

    int k = *a;
    *a=*b;
    *b=k;
}
int partition(int arr[],int low,int hight)
{
    int pivot = arr[hight];
    int i = low-1;
    for(int j = low;j<hight;j++)
    {
        if(arr[j]<=pivot)
        {
            i++;
            swap(&arr[i],&arr[j]);
        }

    }
    swap(arr[i+1],arr[hight]);
    return i+1;

}
void quicksort(int arr[],int low,int hight)
{
    if(low < hight)
    {
        int pivot = partition(arr,low,hight);
        quicksort(arr,low,pivot-1);
        quicksort(arr,pivot+1,hight);
    }
}

int main()
{
    int n,del;
    double Av1=0,Av2=0,Sum=0;

    cin >> n;
    while(n % 2 == 0)
    {
        cout << "Please enter odd number \n" ;
        cin >> n;
    }

    int numbers[n];
    for(int i = 0;i<n;i++)
    {
        cin >> numbers[i];
    }
    quicksort(numbers,0,n-1);
    Av1 = (double)(numbers[0] + numbers[n-1] + numbers[n/2])/3.0;
    cout << "Average for smallest , largest and medium number is: "<<Av1<<"\n";
    for(int i = 1;i<n;i+=2)
    {
        Sum += numbers[i];
    }
    del = n/2;
    Av2 = Sum / del;
    cout << "Average for odd numbers is " << Av2 << "\n";


    // Tocha B

    list<int> list1 ;
    int Element = 0;
    for(int i = 1;i<n;i+=2)
    {
        if(numbers[i]<0)
        {
            if(i==1)
            {
                cout << "There is no two elements before 1 \n";
            }
            else
            {
             Element = 3*(numbers[i-1] + numbers[i-2]);
             list1.push_back(Element);
            }

        }
    }



}
close fullscreen
Login or Register to edit or fork this paste. It's free.