0
Write a program to print the even number from 1to20
8 Respostas
+ 15
for (let stp = 0; stp <= 20; stp+=2) {
document.write(stp);
}
document.close();
+ 4
As you didn't mention the language in which you want the answer, I am giving you the logic. Use a loop from 1 to 20 and print a number if it leaves a remainder of 0 when divided by 2 (n%2==0).
+ 3
@ValentinHacker: your code prints the odd numbers ;)
+ 1
Java
for(int i=0; i<=20; i+=2)
System.out.println(i);
0
or
0
print([x in range(2,21,2)])
print([x in range(21) if x%2==0])
0
for i in range(21):
if i % 2 == 0:
print(i)
0
#include <stdio.h>
main()
{
int i;
for(i = 2; i <= 20; i += 2)
printf("%d\n", i);
return 0;
}