Advertisement
Guest User

Untitled

a guest
May 13th, 2020
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int sum_of_even(int array[10], int length)
  5. {
  6.     int sum = 0, amount = 0;
  7.     for (int i = 0; i < length; i++)
  8.     {
  9.         if (array[i] % 2 == 0)
  10.         {
  11.             sum += array[i];
  12.             amount++;
  13.         }
  14.     }
  15.     if (amount < 1)
  16.     {
  17.         return -1;
  18.     }
  19.     return sum;
  20. }
  21.  
  22.  
  23. int main()
  24. {
  25.     int amount, temp;
  26.     int array[10];
  27.     int entered = 0;
  28.     printf("Enter the amount of input numbers:\n");
  29.     temp = scanf("%d", &amount);
  30.     printf(amount);
  31.     if (temp != 1 || amount > 10 || amount <= 0)
  32.     {
  33.         printf("Input error");
  34.         return 1;
  35.     }
  36.     printf("Enter numbers: \n");
  37.     while (entered < amount)
  38.     {
  39.         temp = scanf("%d", &array[entered]);
  40.         if (temp == 1)
  41.         {
  42.             entered++;
  43.         }
  44.     }
  45.     temp = sum_of_even(array, amount);
  46.     if (temp == -1)
  47.     {
  48.         printf("There is no even numbers");
  49.         return 2;
  50.     }
  51.     printf("%d", temp);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement