Answer:
void main ( )
{
int counter;
cout<<""Even numbers between 1 to 20 are:""<<endl ;
//Method 1
for (counter = 1; counter <= 20; counter++)
{
if ( counter%2 == 0)
{
cout<<counter<<""\t""<<endl ;
}
}
//Method 2 – simplest one
for (counter = 2; counter <= 20;)
{
cout<<counter<<""\t""<<endl ;
counter = counter + 2;
}
return 0;
}
Step-by-step explanation:
In this, Method 1 runs a for loop and check whether each number is divided by 2. If yes, then printed otherwise it is skipped.
In the second method, it runs for loop only for even numbers. This is obtained by incrementing the counter by 2.