Can anyone tell me how to complete this code when I run this code Test case 1,4,5 fails | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone tell me how to complete this code when I run this code Test case 1,4,5 fails

#include <stdio.h> #include <stdlib.h> int main() { int len, i; int sum = 0; int *arr; scanf("%d", &len); arr = (int*) malloc(len * sizeof(int)); for(i=0; i < len; i++) { scanf("%d", arr+i); if(*(arr+i)%2 == 0){ sum += *(arr+1); } } printf("%d", sum); free(arr); return 0; }

28th Jul 2020, 3:26 AM
VIGNESH MARADIYA
VIGNESH MARADIYA - avatar
5 Answers
+ 5
Ipang I suppose he is talking about the "That's odd..." challenge where one have to find the sum of all even integers present in a list of given length N. Let me know if you want all code coach tasks. Vígñësh M@râdīyå Please remember to provide the challenge name or link next time if you want to get fast an accurate help. You have a tiny mistake: sum += *(arr+1); should be: sum += *(arr + i ); You already solved the task in other languages so it's probably a typo.
28th Jul 2020, 4:31 AM
Kevin ★
+ 3
Kevin ★ Thanks bro for help
28th Jul 2020, 4:49 AM
VIGNESH MARADIYA
VIGNESH MARADIYA - avatar
+ 3
Ipang 😅 Vígñësh M@râdīyå You're welcome.
28th Jul 2020, 4:52 AM
Kevin ★
+ 2
What was the task requirement? is this one of the code coaches? I can't view code coaches BTW, so I need to know the task ...
28th Jul 2020, 3:53 AM
Ipang
+ 1
Kevin ★ Thanks for telling 🙏 I suppose he might have gotten it figured out through your notes by now 😁👍
28th Jul 2020, 4:46 AM
Ipang