Algorithm
Even Numbers
Adapted by Neilor Tonin, URI Brazil
Write a program that prints all even numbers between 1 and 100, including them if it is the case.
Input
In this extremely simple problem there is no input.
Output
Print all even numbers between 1 and 100, including them, one by row.
Input Sample | Output Sample |
2 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main()
{
int n = 100,i;
for( i =2; i < = n; i=i+2)
{
printf("%d\n", i);
}
return 0;
}
Copy The Code &
Try With Live Editor
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream<
using namespace std;
int main() {
for (int i = 1; i < = 100; i++) {
if (i % 2 == 0) {
cout << i << endl;
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Output
#3 Code Example with Python Programming
Code -
Python Programming
start, end = 1, 100
# iteration
for num in range(start, end + 1):
# check
if num % 2 == 0:
print(num)
Copy The Code &
Try With Live Editor
Output