- 2
Write a program using for loop that prints even numbers from 0 to 20
4 Respuestas
0
Is this a question or an assignment? Learn how to specify the steps in your loop or use the modulus operator to determine if a number is even.
0
two ways:
1st
int x;
for ( x=0; x <= 20; x = x+2 )
cout<< "This is a even number " << x << ".\n";
}
2nd more optimazed
for ( x=0; x <= 20; x = x+1 )
if (x % 2 = 0)
cout<< "This is a even number " << x << ".\n";
}
0
This is Q
- 1
for(int i=0;i<=20;i=i+2)
Then print i