Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int sum_of_even(int array[10], int length)
- {
- int sum = 0, amount = 0;
- for (int i = 0; i < length; i++)
- {
- if (array[i] % 2 == 0)
- {
- sum += array[i];
- amount++;
- }
- }
- if (amount < 1)
- {
- return -1;
- }
- return sum;
- }
- int main()
- {
- int amount, temp;
- int array[10];
- int entered = 0;
- printf("Enter the amount of input numbers:\n");
- temp = scanf("%d", &amount);
- printf(amount);
- if (temp != 1 || amount > 10 || amount <= 0)
- {
- printf("Input error");
- return 1;
- }
- printf("Enter numbers: \n");
- while (entered < amount)
- {
- temp = scanf("%d", &array[entered]);
- if (temp == 1)
- {
- entered++;
- }
- }
- temp = sum_of_even(array, amount);
- if (temp == -1)
- {
- printf("There is no even numbers");
- return 2;
- }
- printf("%d", temp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement