Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- double m1(double *arr, int n)
- {
- double t, arrange_sum = 0;
- for (int i = 0; i < n; i++)
- {
- t = arr[i] / n;
- arrange_sum += t;
- }
- return arrange_sum;
- }
- double m2(double *arr1, int n)
- {
- double max;
- max = arr1[0];
- for (int i = 1; i < n; i++)
- {
- if (arr1[i] > max)
- max = arr1[i];
- }
- return max;
- }
- int make_a1(double *arr, int n, double arrange_sum)
- {
- int count = n;
- for (int i = 0; i < n; i++)
- {
- for (int k = 0; k < n; k++)
- printf ("%lf ",arr[k]);
- printf("\n");
- if ((arr[i] - arrange_sum) > 1e-10)
- {
- for (int j = i; j < count; j++)
- {
- arr[j] = arr[j+1];
- }
- count--;
- i--;
- }
- }
- return count;
- }
- void make_a2(double *arr, int n, int p, double mu2)
- {
- int i = p;
- double t, t1;
- t = arr[p];
- arr[p] = mu2;
- while (i < n + 1)
- {
- t1 = t;
- t = arr[i];
- arr[i+1] = t1;
- i++;
- }
- }
- void test_m1()
- {
- double eps = 1e-5;
- double rez;
- int err_counter = 0;
- // Test 1
- double a[5] = {1, 2, 3, 4, 5};
- rez = m1(a,5);
- if (fabsf(rez - 3)>eps)
- err_counter++;
- // Test 2
- double a1[4] = {0, 2, 0, 2};
- rez = m1(a1,4);
- if (fabsf(rez - 1) > eps)
- err_counter++;
- // Test 3
- double a2[5] = {1.1, 2.2, 3.3, 4.4, 5.5};
- rez = m1(a2,5);
- if (fabsf(rez - 3.3) > eps)
- err_counter++;
- printf("Error test of m1 function : %s\n", err_counter ? "FAILED" : "OK");
- }
- void test_m2()
- {
- double eps = 1e-5;
- double rez;
- int err_counter = 0;
- // Test 1
- double a[9] = {1, 2, 3, 4, 5, 4, 3, 2, 1};
- rez = m2(a,5);
- if (rez != 5)
- err_counter++;
- // Test 2
- double a1[4] = {0, 2, 0, 2};
- rez = m2(a1,4);
- if (rez != 2)
- err_counter++;
- // Test 3
- double a2[5] = {-5.0, -4.2, -3.4, -2.1, 0};
- rez = m2(a2,5);
- if (rez != 0)
- err_counter++;
- printf("Error test of m2 function : %s\n", err_counter ? "FAILED" : "OK");
- }
- void test_make_a1()
- {
- double eps = 1e-5;
- double rez;
- int err_counter = 0;
- // Test 1
- double a[5] = {1, 2, 3, 4, 5};
- rez = make_a1(a,5, 3);
- printf("rez = %lf\n", rez);
- if (rez != 3)
- err_counter++;
- // Test 2
- double a1[4] = {0, 2, 0, 2};
- rez = make_a1(a1, 4, 0.5);
- if (rez != 2)
- err_counter++;
- // Test 3
- double a2[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- printf("rez = %lf\n", rez);
- rez = make_a1(a2, 10, 5.5);
- printf("rez = %lf\n", rez);
- if (rez != 5)
- err_counter++;
- printf("Error test of make_a1 function : %s\n", err_counter ? "FAILED" : "OK");
- }
- void test_make_a2()
- {
- printf("OK");
- }
- int main()
- {
- double a[10] = {1,2,3,4,5,6,7,8,9,10};
- printf("%lf\n",m1(a,10));
- test_m1();
- test_m2();
- test_make_a1();
- test_make_a2();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment