Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.7 kB
2
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>  
#include <stdlib.h>
#include <conio.h>           
#include <locale.h> 


static int pr = 0;
static int sravn = 0;
void sort(int in[], int n)
{
    {

        for (int i = 1; i < n; i++)
            for (int k = i; k != 0 && in[k] < in[k - 1]; k--)
            {
                sravn = sravn + 2;
                int c = in[k]; in[k] = in[k - 1]; in[k - 1] = c;
                pr = pr + 1;
            }
    }
}



void main()
{

    setlocale(LC_CTYPE, "Russian");
    int i, n, j, A[100], Amax, Amin;
    printf("Enter the number of array elements: ");
    scanf("%i", &n);
    int size = n;
    printf("\n");
    printf("Source array : ");
    for (j = 0; j < n; j++) {
        A[j] = rand() / (2 * n);
        printf("%i ", A[j]);
    }


    //Search for the largest and smallest element
    Amin = A[0], Amax = 0;
    for (i = 0; i < n; i++)
    {
        sravn = sravn + 1;
        if (A[i] < Amin) {
            Amin = A[i]; pr = pr + 1;
        }
        if (A[i] > Amax) {
            Amax = A[i]; sravn = sravn + 1; pr = pr + 1;
        }


    }

    for (i = 0; i < n; i++)
    {

        j = ((A[i] - Amin) * n) / (Amax - Amin);

        sort(A, size);
    }
    printf("\n");
    printf("\n");
    printf("Sorted array : ");
    for (j = 0; j < n; j++) printf("%i ", A[j]);
    printf("\n");
    printf("\n");
    printf("Exchanges : ");
    printf("%i", pr);
    printf("\n");
    printf("Comparisons  : ");
    printf("%i", sravn);
    printf("\n");
    printf("Control value of labor intensity : ");
    printf("%i", ((n * n) / 2));
    _getch();

}