total of even and odd numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

total of even and odd numbers

the code calculates the total of even numbers and odd numbers, but it does not do it from the array, it counts based on the size of the array. How do i solve this problem. For example, if this was an array of 8 12 23 46 24 56 78 89 34 the program will say there are 4 even numbers and 4 odd, which is not true. i need the program to say there are 6 even numbers and 2 odd numbers. https://code.sololearn.com/cW0ZS0KpKb4W/?ref=app

2nd Oct 2021, 3:35 PM
Bobby Dike
Bobby Dike - avatar
7 Answers
+ 3
First of all your program was not printing full list of numbers before calculating number of even and odd numbers. Now it does. Also you was comparing index rather than the array elements, that's why it didn't operate as required. And lastly you had 4 loops in your code. Now it's 2 Here is a fixed version of your code: https://code.sololearn.com/cipV9jfNgzW0/?ref=app
2nd Oct 2021, 3:49 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
No problem mate 👍
3rd Oct 2021, 4:44 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
0
thanks a lot
3rd Oct 2021, 4:33 PM
Bobby Dike
Bobby Dike - avatar
0
i have some other problems
3rd Oct 2021, 4:44 PM
Bobby Dike
Bobby Dike - avatar
0
gimmie a minute
3rd Oct 2021, 4:44 PM
Bobby Dike
Bobby Dike - avatar
0
Aleksei Radchenkov divisible by three and five ive added some other statements but its not working, and it also calculates the numbers divisible by three and five from the array size instead of the random numbers in the array. https://code.sololearn.com/cW0ZS0KpKb4W/?ref=app
3rd Oct 2021, 5:17 PM
Bobby Dike
Bobby Dike - avatar
0
Bobby Dike , that seems to work for me....
3rd Oct 2021, 9:47 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar