Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MAX 20
  4.  
  5.  
  6. int input_arr(int *arr, int n)
  7. {
  8. for (int i = 0; i < n; i++)
  9. {
  10. printf("Input the element of the array: ");
  11. if (scanf("%d", &arr[i]) != 1)
  12. return EXIT_FAILURE;
  13. }
  14. return EXIT_SUCCESS;
  15. }
  16.  
  17. int the_coming_of_number(int *arr, int n)
  18. {
  19. int element = 0;
  20. int next_element = 1;
  21. int flag = 0;
  22.  
  23. for (int i = 0; i < n; i++)
  24. {
  25. if (arr[i] % 3 == 0)
  26. {
  27. for (int j = n - 1; j > i; j--)
  28. {
  29. arr[j + 1] = arr[j];
  30. }
  31. arr[i + 1] = element;
  32. next_element = element + next_element;
  33. element = next_element - element;
  34. flag = 1;
  35. n++;
  36. i++;
  37. }
  38. }
  39. if (flag != 1)
  40. {
  41. printf("Error");
  42. return EXIT_FAILURE;
  43. }
  44. else
  45. {
  46. for (int i = 0; i < n; i++)
  47. printf("%d ", arr[i]);
  48. }
  49. return EXIT_SUCCESS;
  50. }
  51.  
  52. int main()
  53. {
  54. int arr[MAX];
  55. int n;
  56. int rc;
  57.  
  58. printf("Input the number of array elements: ");
  59. rc = scanf("%d", &n);
  60.  
  61. if (rc != 1 || n <= 0 || n > 10)
  62. {
  63. printf("Error");
  64. return EXIT_FAILURE;
  65. }
  66.  
  67. if (input_arr(arr, n) == EXIT_FAILURE)
  68. return EXIT_FAILURE;
  69.  
  70. if (the_coming_of_number(arr, n) == EXIT_FAILURE)
  71. return EXIT_FAILURE;
  72.  
  73. return EXIT_SUCCESS;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement