Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define ERROR -1
- #define OK 0
- #define CORRECT_SCAN 1
- void task_one(double *array, double *array_end, double mu)
- {
- double *ptr = array;
- while (ptr < array_end)
- {
- if (fabs(*ptr) < fabs(mu))
- {
- printf("hui %lf %lf \n ", *ptr, mu);
- double *swap_ptr = ptr;
- double *swap_ptr_step_ahead = swap_ptr;
- swap_ptr_step_ahead++;
- while (swap_ptr < array_end)
- {
- printf("swap_ptr = %lf \n", *swap_ptr);
- swap_ptr = swap_ptr_step_ahead;
- swap_ptr++;
- swap_ptr_step_ahead++;
- }
- array_end--;
- }
- ptr++;
- }
- }
- double average_cubic_modules(double *array, double *array_end)
- {
- double mu = 0;
- int length = array_end - array;
- for (double *ptr = array; ptr < array_end - 1; ptr++)
- {
- mu += pow(fabs(*ptr), 3) / length;
- printf("mu = %lf \n", mu);
- }
- mu = cbrt(mu);
- return mu;
- }
- int input_array(double *array, double *array_end)
- {
- printf("Please input array elements:");
- if (array)
- {
- for (double *ptr = array; ptr < array_end; ptr++)
- {
- if (scanf("%lf", ptr) != CORRECT_SCAN)
- {
- return ERROR;
- }
- }
- }
- else
- {
- return ERROR;
- }
- return OK;
- }
- int main()
- {
- printf("Please input n:");
- int n;
- if (scanf("%d", &n) != CORRECT_SCAN)
- {
- return ERROR;
- }
- double *array = malloc(n * sizeof(double));
- double *array_end = array + n;
- if (input_array(array, array_end) == ERROR)
- {
- return ERROR;
- }
- double mu = average_cubic_modules(array, array_end);
- printf("mu = %lf \n", mu);
- task_one(array, array_end, mu);
- printf("\n");
- for (double *ptr = array; ptr < array_end; ptr++)
- {
- printf("%lf ", *ptr);
- }
- free(array);
- return OK;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement