#Display all even elements greater than 2

1 messages · Page 1 of 1 (latest)

neon yacht
#

What is you actual question? #📄・posting-guidelines Did you try anything?

#

Display all even elements greater than 2

crimson seal
#

Thank you

neon yacht
crimson seal
neon yacht
#

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

crimson seal
#

I tried to use res but it didn’t work

neon yacht
#

Do you have some code?

#

Please take a minute to read the #📄・posting-guidelines

clear ridge
#

;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);
sullen depotBOT
#
Program Output
4,6,8,12,30,44,100,
clear ridge
#

;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();
sullen depotBOT
#
Program Output
4
6
8
12
30
44
100

clear ridge
#

;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;
}

sullen depotBOT
#
Program Output
4,6,8,12,30,44,100,
clear ridge
#

;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;
}

sullen depotBOT
#
Program Output
4,6,8,12,30,44,100,
clear ridge
#

;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();
sullen depotBOT
#
Program Output
4,6,8,12,30,44,100,
clear ridge
#

same logic in almost all C like language

neon yacht
#

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()
sullen depotBOT
#
Program Output
4, 6, 8, 12, 30, 44, 100

neon yacht
#

;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(", ")
sullen depotBOT
#
Program Output
4, 6, 8, 12, 30, 44, 100
neon yacht
#

;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]).
sullen depotBOT
#
Program Output
4, 6, 8, 12, 30, 44, 100, 

clear ridge
#

no python 😂

neon yacht
clear ridge
#

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 + ","); }
 }
}
}
sullen depotBOT
#
Program Output
4,6,8,12,30,44,100,
clear ridge
#

;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);
 }
}

sullen depotBOT
#
Program Output
4
6
8
12
30
44
100
clear ridge
#

;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(", "));
sullen depotBOT
#
Program Output
4, 6, 8, 12, 30, 44, 100

clear ridge
#

;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(", "));