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.
3 Antworten
+ 2
for(i=2;i<=10;i++)
{
if(i%2==0)
{
cout<<i;
}
}
+ 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
+ 1
for (int i=0;i<11;i++)
if(i%2==0)
cout<<i;