Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 10
- int input_arr(int n, int *a)
- {
- for (int i = 0; i < n; i++)
- {
- printf("Input the element of the array: ");
- if (scanf("%d", &a[i]) != 1)
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- int selection(int *main_arr, int *answr_arr, int n)
- {
- int k = 0;
- int flag = 0;
- for (int i = 0; i < n; i++)
- {
- if (main_arr[i] > 1)
- {
- for (int j = 2; j < main_arr[i]; j++)
- {
- if (main_arr[i] % j == 0)
- {
- flag = 1;
- }
- }
- if (flag != 1)
- {
- answr_arr[k] = main_arr[i];
- k++;
- }
- flag = 0;
- }
- }
- if (k == 0)
- {
- printf("There are no prime numbers in the sequence");
- return EXIT_FAILURE;
- }
- else
- {
- for (int i = 0; i < k; i++)
- printf("%d", answr_arr[i]);
- }
- return EXIT_SUCCESS;
- }
- int main()
- {
- int main_arr[MAX];
- int answr_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(n, main_arr) == EXIT_FAILURE)
- return EXIT_FAILURE;
- if (selection(main_arr, answr_arr, n) == EXIT_FAILURE)
- return EXIT_FAILURE;
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement