Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdbool.h>
- /**
- Initially output equals 0. Iterate through each number in the input and perform the following operation:
- If the number is odd: Multiply it to output
- If the number is even: Add it to the output
- Input
- 5
- 2 4 8 10 6
- Output
- 30
- **/
- int main()
- {
- int count;
- scanf("%d", &count);
- int result = 0;
- for (int i = 0; i < count; i++) {
- int number;
- scanf("%d", &number);
- result = number % 2 != 0 ? result * number : result + number;
- }
- printf("%d\n", result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement