An array have ten elements print all even number and their sum in the array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

An array have ten elements print all even number and their sum in the array

28th Aug 2017, 5:21 AM
Ram Varma
Ram Varma - avatar
3 Answers
+ 5
@Svengat: it should with a few corrections. ; () Ram will need to add a sum variable to it as well but yeah this should work fine.
28th Aug 2017, 5:30 AM
jay
jay - avatar
+ 5
Something like this should do it. (using Svengats answer with corrections) int sum = 0; for(int i = 0; i < 10; ++i) { if(arr[i]%2==0){ cout<<arr[i]<<endl; sum+=arr[i]; } } This should also go along way to answering your two other (homework?) questions.
28th Aug 2017, 5:41 AM
jay
jay - avatar
+ 4
for (i=0;i<10;i++){if arr[i]%2==0{cout<<arr[i]<<endl}} //Hopefully the above strip works I am a really beginner at C++
28th Aug 2017, 5:23 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar