Advertisement
Guest User

lab_08_02_1.c

a guest
Sep 19th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define OK 1
  4. #define ERR_INPUT 2
  5. #define ERR_RANGE 3
  6. #define ERR_ALLOCATION 4
  7.  
  8. //Функция ввода.
  9.  
  10. int input(float **array, int *n, int p)
  11. {
  12. float *a = NULL;
  13. printf("Enter n: ");
  14. if(scanf("%d", n) != 1)
  15. return ERR_INPUT;
  16. if(*n <= 0)
  17. return ERR_RANGE;
  18. a = malloc(*n*sizeof(float));
  19. if(a == NULL)
  20. return ERR_ALLOCATION;
  21. printf("Enter elements:\n");
  22. for(int i = 0; i < *n; i++)
  23. {
  24. if (scanf("%f", &a[i]) != 1)
  25. {
  26. free(a);
  27. return ERR_INPUT;
  28. }
  29. }
  30. printf("Enter p: ");
  31. if(scanf("%d", &p) != 1)
  32. return ERR_INPUT;
  33. if(p <= 0 || p >= *n)
  34. return ERR_RANGE;
  35. *array = a;
  36. return OK;
  37. }
  38.  
  39. //Функция вывода.
  40.  
  41. void print(float **array, int n)
  42. {
  43. printf("\nNew Array:\n");
  44. for(int i = 0; i < n; i++)
  45. printf("%f", array[i]);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement