#Display all even elements greater than 2
1 messages · Page 1 of 1 (latest)
Yes this one
Thank you
No, I was asking you, what problem do you have with that.
Like making a code
What you send is not enough to help you. We don't do other people's homework. So, you need to explain what you tried and why you are unable to do it
I tried to use res but it didn’t work
;compile perl
sub main()
{
my @list = qw(1 2 3 4 5 6 7 8 9 12 30 44 45 100 101);
my $n = $#list;
for(my $i = 0; $i < $n; ++$i)
{
my $v = $list[$i];
if ( (($v % 2) == 0) && ($v > 2) )
{ print "$v,"; }
}
}
main();
exit(0);
Program Output
4,6,8,12,30,44,100,
fd26#0000 | perl | perl-5.38.0 | wandbox.org
;compile js
function main()
{
var list = "1 2 3 4 5 6 7 8 9 12 30 44 45 100 101".split(" ");
var $n = list.length;
for(var $i = 0; $i < $n; ++$i)
{
var $v = list[$i];
if ( (($v % 2) == 0) && ($v > 2) )
{ console.log($v); }
}
}
main();
Program Output
4
6
8
12
30
44
100
fd26#0000 | javascript | nodejs-16.14.0 | wandbox.org
;compile c++
#include <stdio.h>
#include <initializer_list>
#include <vector>
#include <iostream>
int main()
{
const std::vector<int> lst = {1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 30, 44, 45, 100, 101};
const int n = lst.size();
for(int i = 0; i < n; ++i)
{
const int v = lst[i];
if ( ((v % 2) == 0) && (v > 2) )
{ std::cout << v << ","; }
}
return 0;
}
Program Output
4,6,8,12,30,44,100,
fd26#0000 | 29ms | c++ | x86-64 gcc 13.2 | godbolt.org
;compile c
#include <stdio.h>
static const int lst[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 30, 44, 45, 100, 101};
int main()
{
const int n = sizeof(lst) / sizeof(int);
for(int i = 0; i < n; ++i)
{
const int v = lst[i];
if ( ((v % 2) == 0) && (v > 2) )
{ printf("%d,", v); }
}
return 0;
}
Program Output
4,6,8,12,30,44,100,
fd26#0000 | 25ms | c | x86-64 gcc 13.2 | godbolt.org
;compile php
<?php
function main()
{
$list = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 30, 44, 45, 100, 101);
$n = count($list);
for($i = 0; $i < $n; ++$i)
{
$v = $list[$i];
if ( (($v % 2) == 0) && ($v > 2) )
{ print ("$v,"); }
}
}
main();
Program Output
4,6,8,12,30,44,100,
fd26#0000 | php | php-8.2.1 | wandbox.org
same logic in almost all C like language
You're having fun XD
;compile
[1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 30, 44, 45, 100, 101]
|> Enum.filter(fn e -> rem(e, 2) == 0 and e > 2 end)
|> Enum.join(", ")
|> IO.puts()
Program Output
4, 6, 8, 12, 30, 44, 100
malassi#0000 | elixir | elixir-1.11.4 | wandbox.org
;compile
elements = [1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 30, 44, 45, 100, 101]
puts elements.select { |e| e % 2 == 0 && e > 2 }.join(", ")
Program Output
4, 6, 8, 12, 30, 44, 100
malassi#0000 | 68ms | ruby | Ruby 3.0.2 | godbolt.org
;compile
-module(prog).
-export([main/0]).
main() ->
Elements = [1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 30, 44, 45, 100, 101],
Filtered = lists:flatten([integer_to_list(E) ++ ", " || E <- Elements, E rem 2 =:= 0, E > 2, E /= lists:last(Elements)]),
io:format("~s~n", [Filtered]).
Program Output
4, 6, 8, 12, 30, 44, 100,
malassi#0000 | erlang | erlang-23.3.1 | wandbox.org
no python 😂
Nah, otherwise we just give the solution XD
honnn 😢
;compile java
import java.util.*;
public class M {
public static void main(String[] args)
{
final List<Integer> lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 30, 44, 45, 100, 101);
final int n = lst.size();
for(int i = 0; i < n; ++i)
{
final int v = lst.get(i);
if ( ((v % 2) == 0) && (v > 2) )
{ System.out.print(v + ","); }
}
}
}
Program Output
4,6,8,12,30,44,100,
fd26#0000 | 78ms | java | jdk 21.0.0 | godbolt.org
;compile java
import java.util.*;
public class M {
public static void main(String[] args)
{
final List<Integer> lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 30, 44, 45, 100, 101);
lst.stream()
.filter( (v) -> ((v % 2) == 0) && (v > 2))
.forEach(System.out::println);
}
}
Program Output
4
6
8
12
30
44
100
fd26#0000 | 93ms | java | jdk 21.0.0 | godbolt.org
;compile js
var lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 30, 44, 45, 100, 101];
lst = lst.filter( (v) => ((v % 2) == 0) && (v > 2));
console.log(lst.join(", "));
Program Output
4, 6, 8, 12, 30, 44, 100
fd26#0000 | javascript | nodejs-16.14.0 | wandbox.org
;compile js
var lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 30, 44, 45, 100, 101];
lst = lst.filter(function(v){ return ((v % 2) == 0) && (v > 2) });
console.log(lst.join(", "));