Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define OK 1
- #define ERR_INPUT 2
- #define ERR_RANGE 3
- #define ERR_ALLOCATION 4
- //Функция ввода.
- int input(float **array, int *n, int p)
- {
- float *a = NULL;
- printf("Enter n: ");
- if(scanf("%d", n) != 1)
- return ERR_INPUT;
- if(*n <= 0)
- return ERR_RANGE;
- a = malloc(*n*sizeof(float));
- if(a == NULL)
- return ERR_ALLOCATION;
- printf("Enter elements:\n");
- for(int i = 0; i < *n; i++)
- {
- if (scanf("%f", &a[i]) != 1)
- {
- free(a);
- return ERR_INPUT;
- }
- }
- printf("Enter p: ");
- if(scanf("%d", &p) != 1)
- return ERR_INPUT;
- if(p <= 0 || p >= *n)
- return ERR_RANGE;
- *array = a;
- return OK;
- }
- //Функция вывода.
- void print(float **array, int n)
- {
- printf("\nNew Array:\n");
- for(int i = 0; i < n; i++)
- printf("%f", array[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement