0
My solution to "That's odd" doesn't work, and I dont'understand why. The #4 case remains always wrong.[SOLVED]
#include <iostream> using namespace std; int main() { int N, *p, i, out=0; cin >> N;//how many numbers? if(N<=0) return (-1); p = (int *)malloc(sizeof(int)); for(i=0;i<N;i++) { cin>>p[i]; if(p[i]%2==0) out+=p[i]; } cout << out; return 0; }
2 Respostas
+ 1
Resolved. I forgot to multiply the memory in the pointer to N. I had to do:
p = (int *)malloc(N*sizeof(int));
+ 1
p[i] % 2 == 0 -> here you check if a number is even (divisible by 2)
But you need to add odd numbers.
p[i] % 2 != 0 or p[i] % 2 == 1