Advertisement
MonsterScripter

CodinGame_2023_08_22__22_07_45__even_multiply.c

Aug 22nd, 2023
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5.  
  6. /**
  7. Initially output equals 0. Iterate through each number in the input and perform the following operation:
  8. If the number is odd: Multiply it to output
  9. If the number is even: Add it to the output
  10.  
  11. Input
  12. 5
  13. 2 4 8 10 6
  14.  
  15. Output
  16. 30
  17.  
  18.  **/
  19.  
  20. int main()
  21. {
  22.     int count;
  23.     scanf("%d", &count);
  24.     int result = 0;
  25.     for (int i = 0; i < count; i++) {
  26.         int number;
  27.         scanf("%d", &number);
  28.         result = number % 2 != 0 ? result * number : result + number;
  29.     }
  30.     printf("%d\n", result);
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement