SHARE
TWEET

Untitled

a guest Sep 21st, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define ERROR -1
  6. #define OK 0
  7. #define CORRECT_SCAN 1
  8.  
  9. void task_one(double *array, double *array_end, double mu)
  10. {
  11.     double *ptr = array;
  12.     while (ptr < array_end)
  13.     {
  14.         if (fabs(*ptr) < fabs(mu))
  15.         {
  16.             printf("hui %lf %lf \n ", *ptr, mu);
  17.             double *swap_ptr = ptr;
  18.             double *swap_ptr_step_ahead = swap_ptr;
  19.             swap_ptr_step_ahead++;
  20.             while (swap_ptr < array_end)
  21.             {
  22.                 printf("swap_ptr = %lf \n", *swap_ptr);
  23.                 swap_ptr = swap_ptr_step_ahead;
  24.                 swap_ptr++;
  25.                 swap_ptr_step_ahead++;
  26.             }
  27.             array_end--;
  28.         }
  29.         ptr++;
  30.     }
  31. }
  32.  
  33. double average_cubic_modules(double *array, double *array_end)
  34. {
  35.     double mu = 0;
  36.     int length = array_end - array;
  37.     for (double *ptr = array; ptr < array_end - 1; ptr++)
  38.     {
  39.         mu += pow(fabs(*ptr), 3) / length;
  40.         printf("mu = %lf \n", mu);
  41.     }
  42.     mu = cbrt(mu);
  43.     return mu;
  44. }
  45.  
  46. int input_array(double *array, double *array_end)
  47. {
  48.     printf("Please input array elements:");
  49.     if (array)
  50.     {
  51.         for (double *ptr = array; ptr < array_end; ptr++)
  52.         {
  53.             if (scanf("%lf", ptr) != CORRECT_SCAN)
  54.             {
  55.                 return ERROR;
  56.             }
  57.         }
  58.     }
  59.     else
  60.     {
  61.         return ERROR;
  62.     }
  63.     return OK;
  64. }
  65.  
  66. int main()
  67. {
  68.     printf("Please input n:");
  69.     int n;
  70.     if (scanf("%d", &n) != CORRECT_SCAN)
  71.     {
  72.         return ERROR;
  73.     }
  74.     double *array = malloc(n * sizeof(double));
  75.     double *array_end = array + n;
  76.     if (input_array(array, array_end) == ERROR)
  77.     {
  78.         return ERROR;
  79.     }
  80.     double mu = average_cubic_modules(array, array_end);
  81.     printf("mu = %lf \n", mu);
  82.     task_one(array, array_end, mu);
  83.     printf("\n");
  84.     for (double *ptr = array; ptr < array_end; ptr++)
  85.     {
  86.         printf("%lf ", *ptr);
  87.     }
  88.     free(array);
  89.     return OK;
  90. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top