SHARE
TWEET

Untitled

a guest Apr 24th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. #define OK 0
  4. #define ERROR_INPUT 1
  5. #define CORRECT_ELEM 1
  6. #define MAX_SIZE 10
  7. #define MIN_SIZE 1
  8. #define NO_NEW_NUMBERS 2
  9.  
  10. int check_number(int n)
  11. {
  12.     int last = n % 10;
  13.     while (n > 9)
  14.         n /= 10;
  15.     if (n == last)
  16.         return 1;
  17.     return 0;
  18. }
  19.  
  20. void print_arr(int arr[], int size)
  21. {
  22.     for (int i = 0; i < size; i++)
  23.         printf("%d ", arr[i]);
  24. }
  25.  
  26. int arr_input(int arr[], int size, int new_arr[], int *pointer_new_size)
  27. {
  28.     int new_el = 0;
  29.     int res = 0;
  30.     puts("Enter arr: ");
  31.     for (int i = 0; i < size; i++)
  32.     {
  33.         new_el += scanf("%d", &arr[i]);
  34.         res = check_number(arr[i]);
  35.         if (res)
  36.         {
  37.             new_arr[*pointer_new_size] = arr[i];
  38.             *pointer_new_size += 1;
  39.         }
  40.     }
  41.     if (new_el != size)
  42.         return ERROR_INPUT;
  43.  
  44.     print_arr(new_arr, *pointer_new_size);
  45.  
  46.     return OK;
  47. }
  48.  
  49. int main()
  50. {
  51.     int arr_size = 0;
  52.  
  53.     int new_size = 0;
  54.     int *pointer_new_size = &new_size;
  55.  
  56.     int arr[MAX_SIZE] = { 0 };
  57.     int new_arr[MAX_SIZE] = { 0 };
  58.  
  59.     puts("Enter arr size: ");
  60.     int check_input = scanf("%d", &arr_size);
  61.     if (check_input != CORRECT_ELEM || arr_size > MAX_SIZE || arr_size < MIN_SIZE)
  62.         return ERROR_INPUT;
  63.  
  64.     check_input = arr_input(arr, arr_size, new_arr, pointer_new_size);
  65.     if (check_input)
  66.         return ERROR_INPUT;
  67.  
  68.     if (new_size == 0)
  69.         return NO_NEW_NUMBERS;
  70.  
  71.     return OK;
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top