Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 20
- int input_arr(int *arr, int n)
- {
- for (int i = 0; i < n; i++)
- {
- printf("Input the element of the array: ");
- if (scanf("%d", &arr[i]) != 1)
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- int the_coming_of_number(int *arr, int n)
- {
- int element = 0;
- int next_element = 1;
- int flag = 0;
- for (int i = 0; i < n; i++)
- {
- if (arr[i] % 3 == 0)
- {
- for (int j = n - 1; j > i; j--)
- {
- arr[j + 1] = arr[j];
- }
- arr[i + 1] = element;
- next_element = element + next_element;
- element = next_element - element;
- flag = 1;
- n++;
- i++;
- }
- }
- if (flag != 1)
- {
- printf("Error");
- return EXIT_FAILURE;
- }
- else
- {
- for (int i = 0; i < n; i++)
- printf("%d ", arr[i]);
- }
- return EXIT_SUCCESS;
- }
- int main()
- {
- int arr[MAX];
- int n;
- int rc;
- printf("Input the number of array elements: ");
- rc = scanf("%d", &n);
- if (rc != 1 || n <= 0 || n > 10)
- {
- printf("Error");
- return EXIT_FAILURE;
- }
- if (input_arr(arr, n) == EXIT_FAILURE)
- return EXIT_FAILURE;
- if (the_coming_of_number(arr, n) == EXIT_FAILURE)
- return EXIT_FAILURE;
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement