0

Write a program to print the even number from 1to20

24th Feb 2017, 11:11 AM
Vishnu Jaiswal
Vishnu Jaiswal - avatar
8 Antworten
+ 15
for (let stp = 0; stp <= 20; stp+=2) { document.write(stp); } document.close();
24th Feb 2017, 11:23 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 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).
24th Feb 2017, 11:50 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 3
@ValentinHacker: your code prints the odd numbers ;)
24th Feb 2017, 4:00 PM
Mario L.
Mario L. - avatar
+ 1
Java for(int i=0; i<=20; i+=2) System.out.println(i);
4th Mar 2017, 6:48 PM
0xCAFEBABE
0xCAFEBABE - avatar
0
or
24th Feb 2017, 11:26 AM
Vishnu Jaiswal
Vishnu Jaiswal - avatar
0
print([x in range(2,21,2)]) print([x in range(21) if x%2==0])
24th Feb 2017, 12:24 PM
karlxu
karlxu - avatar
0
for i in range(21): if i % 2 == 0: print(i)
24th Feb 2017, 12:28 PM
DerpyOmnister
DerpyOmnister - avatar
0
#include <stdio.h> main() { int i; for(i = 2; i <= 20; i += 2) printf("%d\n", i); return 0; }
21st Mar 2017, 9:02 AM
Thomas Sankara
Thomas Sankara - avatar