0

Need help writing code using a “for” loop!

Write the C++ code for a “for” loop that will output even numbers from 2 to 10.

19th Oct 2017, 3:00 AM
itsTommee
itsTommee - avatar
3 Answers
+ 2
for(i=2;i<=10;i++) { if(i%2==0) { cout<<i; } }
19th Oct 2017, 3:16 AM
Nanda Balakrishnan
+ 1
int main() { for (int a = 2; a <=10; a+=2) { cout << a << endl; } return 0; } \\ I took a=2...so that program will start from 2. a+=2...i.e,a=a+2
19th Oct 2017, 5:01 AM
Blue!!
Blue!! - avatar
+ 1
for (int i=0;i<11;i++) if(i%2==0) cout<<i;
19th Oct 2017, 10:59 AM
Saurabh Talmale
Saurabh Talmale - avatar