+ 1

//code coach problem! "That's odd" task: We want to take a list of numbers and find the sum of all of the only even numbers.

Please tell where I am going wrong?? #include <stdio.h> int main() { int num, num2, sum1 = 0,sum =0; scanf("%d",&num); for(int i = 0; i < num; i++){ scanf("%d",&num2); if(num2 % 2 ==0){ sum1= sum1+num2; printf("%d",sum1); } else{ printf("%d",sum); } } return 0; }

22nd Sep 2020, 8:56 AM
Rupali Haldiya
Rupali Haldiya - avatar
7 Antworten
+ 2
#include <stdio.h> int main() { int num, num2, sum1 = 0; scanf("%d",&num); for(int i = 0; i < num; i++){ scanf("%d",&num2); if(num2 % 2 ==0){ sum1= sum1+num2; } else{ continue ; } } printf("%d",sum1); return 0; } Now try this code
22nd Sep 2020, 12:05 PM
Pon Balaji
Pon Balaji - avatar
+ 2
Thank you Jayakrishna sir , thank you pon Balaji sir, I've got it!!! 😇
22nd Sep 2020, 2:01 PM
Rupali Haldiya
Rupali Haldiya - avatar
+ 1
rupali You may not read question properly... Read again.. It need to find total sum of all even numbers in list. But you are printing as a sequence.. It need only one output total even's sum..
22nd Sep 2020, 12:02 PM
Jayakrishna 🇮🇳
+ 1
rupali thank you
22nd Sep 2020, 2:25 PM
Pon Balaji
Pon Balaji - avatar
0
rupali , post in your question the whole description of the task, so someone can help you.
22nd Sep 2020, 9:21 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
You're welcome.. rupali
22nd Sep 2020, 3:46 PM
Jayakrishna 🇮🇳