WeixiangYan/CodeTransOcean huggingface dataset:
Task: Handle a signal





Java: import sun.misc.Signal;
import sun.misc.SignalHandler;

public class ExampleSignalHandler {
    public static void main(String... args) throws InterruptedException {
        final long start = System.nanoTime();
        Signal.handle(new Signal("INT"), new SignalHandler() {
            public void handle(Signal sig) {
                System.out.format("\nProgram execution took %f seconds\n", (System.nanoTime() - start) / 1e9f);
                System.exit(0);
            }
        });
        int counter = 0;
        while(true) {
            System.out.println(counter++);
            Thread.sleep(500);
        }
    }
}


PHP: <?php
declare(ticks = 1);

$start = microtime(true);

function mySigHandler() {
  global $start;
  $elapsed = microtime(true) - $start;
  echo "Ran for $elapsed seconds.\n";
  exit();
}

pcntl_signal(SIGINT, 'mySigHandler');

for ($n = 0; ; usleep(500000)) // 0.5 seconds
   echo ++$n, "\n";
?>
Task: Handle a signal






PHP: <?php
declare(ticks = 1);

$start = microtime(true);

function mySigHandler() {
  global $start;
  $elapsed = microtime(true) - $start;
  echo "Ran for $elapsed seconds.\n";
  exit();
}

pcntl_signal(SIGINT, 'mySigHandler');

for ($n = 0; ; usleep(500000)) // 0.5 seconds
   echo ++$n, "\n";
?>


Python: import time

def counter():
    n = 0
    t1 = time.time()
    while True:
        try:
            time.sleep(0.5)
            n += 1
            print n
        except KeyboardInterrupt, e:
            print 'Program has run for %5.3f seconds.' % (time.time() - t1)
            break

counter()
Task: Handle a signal






PHP: <?php
declare(ticks = 1);

$start = microtime(true);

function mySigHandler() {
  global $start;
  $elapsed = microtime(true) - $start;
  echo "Ran for $elapsed seconds.\n";
  exit();
}

pcntl_signal(SIGINT, 'mySigHandler');

for ($n = 0; ; usleep(500000)) // 0.5 seconds
   echo ++$n, "\n";
?>



VB: Module Module1
    Dim startTime As Date

    Sub Main()
        startTime = Date.Now
        
        AddHandler Console.CancelKeyPress, AddressOf Console_CancelKeyPress

        Dim counter = 0
        While True
            counter += 1
            Console.WriteLine(counter)
            Threading.Thread.Sleep(500)
        End While
    End Sub

    Sub Console_CancelKeyPress(sender As Object, e As ConsoleCancelEventArgs)
        Dim stopTime = Date.Now
        Console.WriteLine("This program ran for {0:000.000} seconds", (stopTime - startTime).TotalMilliseconds / 1000)
        Environment.Exit(0)
    End Sub

End Module
Task: Fibonacci sequence

C: 
fun fibb
    loop
        a = funparam[0]
        break (a < 2)

        a--

        
        a -> stack

        
        funparam[0] = a
        call fibb

        
        b = funparam[0]
        stack -> a

        
        b -> stack

        a--

        
        funparam[0] = a
        call fibb

        
        c = funparam[0]
        stack -> b

        
        b += c
        a = b

        funparam[0] = a

        break
    end
end





C#: public static ulong Fib(uint n) {
    return (n < 2)? n : Fib(n - 1) + Fib(n - 2);
}
Task: Fibonacci sequence

C: 
fun fibb
    loop
        a = funparam[0]
        break (a < 2)

        a--

        
        a -> stack

        
        funparam[0] = a
        call fibb

        
        b = funparam[0]
        stack -> a

        
        b -> stack

        a--

        
        funparam[0] = a
        call fibb

        
        c = funparam[0]
        stack -> b

        
        b += c
        a = b

        funparam[0] = a

        break
    end
end




C++: #include <iostream>

int main()
{
        unsigned int a = 1, b = 1;
        unsigned int target = 48;
        for(unsigned int n = 3; n <= target; ++n)
        {
                unsigned int fib = a + b;
                std::cout << "F("<< n << ") = " << fib << std::endl;
                a = b;
                b = fib;
        }

        return 0;
}
Task: Fibonacci sequence

C: 
fun fibb
    loop
        a = funparam[0]
        break (a < 2)

        a--

        
        a -> stack

        
        funparam[0] = a
        call fibb

        
        b = funparam[0]
        stack -> a

        
        b -> stack

        a--

        
        funparam[0] = a
        call fibb

        
        c = funparam[0]
        stack -> b

        
        b += c
        a = b

        funparam[0] = a

        break
    end
end






Go: func fib(a int) int {
  if a < 2 {
    return a
  }
  return fib(a - 1) + fib(a - 2)
}
Task: Fibonacci sequence

C: 
fun fibb
    loop
        a = funparam[0]
        break (a < 2)

        a--

        
        a -> stack

        
        funparam[0] = a
        call fibb

        
        b = funparam[0]
        stack -> a

        
        b -> stack

        a--

        
        funparam[0] = a
        call fibb

        
        c = funparam[0]
        stack -> b

        
        b += c
        a = b

        funparam[0] = a

        break
    end
end







Java: public static long itFibN(int n)
{
 if (n < 2)
  return n;
 long ans = 0;
 long n1 = 0;
 long n2 = 1;
 for(n--; n > 0; n--)
 {
  ans = n1 + n2;
  n1 = n2;
  n2 = ans;
 }
 return ans;
}
Task: Fibonacci sequence

C: 
fun fibb
    loop
        a = funparam[0]
        break (a < 2)

        a--

        
        a -> stack

        
        funparam[0] = a
        call fibb

        
        b = funparam[0]
        stack -> a

        
        b -> stack

        a--

        
        funparam[0] = a
        call fibb

        
        c = funparam[0]
        stack -> b

        
        b += c
        a = b

        funparam[0] = a

        break
    end
end









Python: from math import *

def analytic_fibonacci(n):
  sqrt_5 = sqrt(5);
  p = (1 + sqrt_5) / 2;
  q = 1/p;
  return int( (p**n + q**n) / sqrt_5 + 0.5 )

for i in range(1,31):
  print analytic_fibonacci(i),
Task: Fibonacci sequence

C: 
fun fibb
    loop
        a = funparam[0]
        break (a < 2)

        a--

        
        a -> stack

        
        funparam[0] = a
        call fibb

        
        b = funparam[0]
        stack -> a

        
        b -> stack

        a--

        
        funparam[0] = a
        call fibb

        
        c = funparam[0]
        stack -> b

        
        b += c
        a = b

        funparam[0] = a

        break
    end
end










VB: Public Function Fib(ByVal n As Integer) As Variant
    Dim fib0 As Variant, fib1 As Variant, sum As Variant
    Dim i As Integer
    fib0 = 0
    fib1 = 1
    For i = 1 To n
        sum = fib0 + fib1
        fib0 = fib1
        fib1 = sum
    Next i
    Fib = fib0
End Function
Task: Fibonacci sequence


C++: #include <iostream>

int main()
{
        unsigned int a = 1, b = 1;
        unsigned int target = 48;
        for(unsigned int n = 3; n <= target; ++n)
        {
                unsigned int fib = a + b;
                std::cout << "F("<< n << ") = " << fib << std::endl;
                a = b;
                b = fib;
        }

        return 0;
}


C#: public static ulong Fib(uint n) {
    return (n < 2)? n : Fib(n - 1) + Fib(n - 2);
}
Task: Fibonacci sequence


C++: #include <iostream>

int main()
{
        unsigned int a = 1, b = 1;
        unsigned int target = 48;
        for(unsigned int n = 3; n <= target; ++n)
        {
                unsigned int fib = a + b;
                std::cout << "F("<< n << ") = " << fib << std::endl;
                a = b;
                b = fib;
        }

        return 0;
}



Go: func fib(a int) int {
  if a < 2 {
    return a
  }
  return fib(a - 1) + fib(a - 2)
}
Task: Fibonacci sequence


C++: #include <iostream>

int main()
{
        unsigned int a = 1, b = 1;
        unsigned int target = 48;
        for(unsigned int n = 3; n <= target; ++n)
        {
                unsigned int fib = a + b;
                std::cout << "F("<< n << ") = " << fib << std::endl;
                a = b;
                b = fib;
        }

        return 0;
}




Java: public static long itFibN(int n)
{
 if (n < 2)
  return n;
 long ans = 0;
 long n1 = 0;
 long n2 = 1;
 for(n--; n > 0; n--)
 {
  ans = n1 + n2;
  n1 = n2;
  n2 = ans;
 }
 return ans;
}
Task: Fibonacci sequence


C++: #include <iostream>

int main()
{
        unsigned int a = 1, b = 1;
        unsigned int target = 48;
        for(unsigned int n = 3; n <= target; ++n)
        {
                unsigned int fib = a + b;
                std::cout << "F("<< n << ") = " << fib << std::endl;
                a = b;
                b = fib;
        }

        return 0;
}






Python: from math import *

def analytic_fibonacci(n):
  sqrt_5 = sqrt(5);
  p = (1 + sqrt_5) / 2;
  q = 1/p;
  return int( (p**n + q**n) / sqrt_5 + 0.5 )

for i in range(1,31):
  print analytic_fibonacci(i),
Task: Fibonacci sequence


C++: #include <iostream>

int main()
{
        unsigned int a = 1, b = 1;
        unsigned int target = 48;
        for(unsigned int n = 3; n <= target; ++n)
        {
                unsigned int fib = a + b;
                std::cout << "F("<< n << ") = " << fib << std::endl;
                a = b;
                b = fib;
        }

        return 0;
}







VB: Public Function Fib(ByVal n As Integer) As Variant
    Dim fib0 As Variant, fib1 As Variant, sum As Variant
    Dim i As Integer
    fib0 = 0
    fib1 = 1
    For i = 1 To n
        sum = fib0 + fib1
        fib0 = fib1
        fib1 = sum
    Next i
    Fib = fib0
End Function
Task: Fibonacci sequence



C#: public static ulong Fib(uint n) {
    return (n < 2)? n : Fib(n - 1) + Fib(n - 2);
}


Go: func fib(a int) int {
  if a < 2 {
    return a
  }
  return fib(a - 1) + fib(a - 2)
}
Task: Fibonacci sequence



C#: public static ulong Fib(uint n) {
    return (n < 2)? n : Fib(n - 1) + Fib(n - 2);
}






VB: Public Function Fib(ByVal n As Integer) As Variant
    Dim fib0 As Variant, fib1 As Variant, sum As Variant
    Dim i As Integer
    fib0 = 0
    fib1 = 1
    For i = 1 To n
        sum = fib0 + fib1
        fib0 = fib1
        fib1 = sum
    Next i
    Fib = fib0
End Function
Task: Fibonacci sequence





Java: public static long itFibN(int n)
{
 if (n < 2)
  return n;
 long ans = 0;
 long n1 = 0;
 long n2 = 1;
 for(n--; n > 0; n--)
 {
  ans = n1 + n2;
  n1 = n2;
  n2 = ans;
 }
 return ans;
}



Python: from math import *

def analytic_fibonacci(n):
  sqrt_5 = sqrt(5);
  p = (1 + sqrt_5) / 2;
  q = 1/p;
  return int( (p**n + q**n) / sqrt_5 + 0.5 )

for i in range(1,31):
  print analytic_fibonacci(i),
Task: Fibonacci sequence





Java: public static long itFibN(int n)
{
 if (n < 2)
  return n;
 long ans = 0;
 long n1 = 0;
 long n2 = 1;
 for(n--; n > 0; n--)
 {
  ans = n1 + n2;
  n1 = n2;
  n2 = ans;
 }
 return ans;
}




VB: Public Function Fib(ByVal n As Integer) As Variant
    Dim fib0 As Variant, fib1 As Variant, sum As Variant
    Dim i As Integer
    fib0 = 0
    fib1 = 1
    For i = 1 To n
        sum = fib0 + fib1
        fib0 = fib1
        fib1 = sum
    Next i
    Fib = fib0
End Function
Task: Fibonacci sequence



C#: public static ulong Fib(uint n) {
    return (n < 2)? n : Fib(n - 1) + Fib(n - 2);
}



Java: public static long itFibN(int n)
{
 if (n < 2)
  return n;
 long ans = 0;
 long n1 = 0;
 long n2 = 1;
 for(n--; n > 0; n--)
 {
  ans = n1 + n2;
  n1 = n2;
  n2 = ans;
 }
 return ans;
}
Task: Fibonacci sequence



C#: public static ulong Fib(uint n) {
    return (n < 2)? n : Fib(n - 1) + Fib(n - 2);
}





Python: from math import *

def analytic_fibonacci(n):
  sqrt_5 = sqrt(5);
  p = (1 + sqrt_5) / 2;
  q = 1/p;
  return int( (p**n + q**n) / sqrt_5 + 0.5 )

for i in range(1,31):
  print analytic_fibonacci(i),
Task: Fibonacci sequence




Go: func fib(a int) int {
  if a < 2 {
    return a
  }
  return fib(a - 1) + fib(a - 2)
}


Java: public static long itFibN(int n)
{
 if (n < 2)
  return n;
 long ans = 0;
 long n1 = 0;
 long n2 = 1;
 for(n--; n > 0; n--)
 {
  ans = n1 + n2;
  n1 = n2;
  n2 = ans;
 }
 return ans;
}
Task: Fibonacci sequence







Python: from math import *

def analytic_fibonacci(n):
  sqrt_5 = sqrt(5);
  p = (1 + sqrt_5) / 2;
  q = 1/p;
  return int( (p**n + q**n) / sqrt_5 + 0.5 )

for i in range(1,31):
  print analytic_fibonacci(i),


VB: Public Function Fib(ByVal n As Integer) As Variant
    Dim fib0 As Variant, fib1 As Variant, sum As Variant
    Dim i As Integer
    fib0 = 0
    fib1 = 1
    For i = 1 To n
        sum = fib0 + fib1
        fib0 = fib1
        fib1 = sum
    Next i
    Fib = fib0
End Function
Task: Fibonacci sequence




Go: func fib(a int) int {
  if a < 2 {
    return a
  }
  return fib(a - 1) + fib(a - 2)
}




Python: from math import *

def analytic_fibonacci(n):
  sqrt_5 = sqrt(5);
  p = (1 + sqrt_5) / 2;
  q = 1/p;
  return int( (p**n + q**n) / sqrt_5 + 0.5 )

for i in range(1,31):
  print analytic_fibonacci(i),
Task: Fibonacci sequence




Go: func fib(a int) int {
  if a < 2 {
    return a
  }
  return fib(a - 1) + fib(a - 2)
}





VB: Public Function Fib(ByVal n As Integer) As Variant
    Dim fib0 As Variant, fib1 As Variant, sum As Variant
    Dim i As Integer
    fib0 = 0
    fib1 = 1
    For i = 1 To n
        sum = fib0 + fib1
        fib0 = fib1
        fib1 = sum
    Next i
    Fib = fib0
End Function
Task: Fibonacci sequence

C: 
fun fibb
    loop
        a = funparam[0]
        break (a < 2)

        a--

        
        a -> stack

        
        funparam[0] = a
        call fibb

        
        b = funparam[0]
        stack -> a

        
        b -> stack

        a--

        
        funparam[0] = a
        call fibb

        
        c = funparam[0]
        stack -> b

        
        b += c
        a = b

        funparam[0] = a

        break
    end
end








PHP: function fibIter($n) {
    if ($n < 2) {
        return $n;
    }
    $fibPrev = 0;
    $fib = 1;
    foreach (range(1, $n-1) as $i) {
        list($fibPrev, $fib) = array($fib, $fib + $fibPrev);
    }
    return $fib;
}
Task: Fibonacci sequence



C#: public static ulong Fib(uint n) {
    return (n < 2)? n : Fib(n - 1) + Fib(n - 2);
}




PHP: function fibIter($n) {
    if ($n < 2) {
        return $n;
    }
    $fibPrev = 0;
    $fib = 1;
    foreach (range(1, $n-1) as $i) {
        list($fibPrev, $fib) = array($fib, $fib + $fibPrev);
    }
    return $fib;
}
Task: Fibonacci sequence


C++: #include <iostream>

int main()
{
        unsigned int a = 1, b = 1;
        unsigned int target = 48;
        for(unsigned int n = 3; n <= target; ++n)
        {
                unsigned int fib = a + b;
                std::cout << "F("<< n << ") = " << fib << std::endl;
                a = b;
                b = fib;
        }

        return 0;
}





PHP: function fibIter($n) {
    if ($n < 2) {
        return $n;
    }
    $fibPrev = 0;
    $fib = 1;
    foreach (range(1, $n-1) as $i) {
        list($fibPrev, $fib) = array($fib, $fib + $fibPrev);
    }
    return $fib;
}
Task: Fibonacci sequence




Go: func fib(a int) int {
  if a < 2 {
    return a
  }
  return fib(a - 1) + fib(a - 2)
}



PHP: function fibIter($n) {
    if ($n < 2) {
        return $n;
    }
    $fibPrev = 0;
    $fib = 1;
    foreach (range(1, $n-1) as $i) {
        list($fibPrev, $fib) = array($fib, $fib + $fibPrev);
    }
    return $fib;
}
Task: Fibonacci sequence





Java: public static long itFibN(int n)
{
 if (n < 2)
  return n;
 long ans = 0;
 long n1 = 0;
 long n2 = 1;
 for(n--; n > 0; n--)
 {
  ans = n1 + n2;
  n1 = n2;
  n2 = ans;
 }
 return ans;
}


PHP: function fibIter($n) {
    if ($n < 2) {
        return $n;
    }
    $fibPrev = 0;
    $fib = 1;
    foreach (range(1, $n-1) as $i) {
        list($fibPrev, $fib) = array($fib, $fib + $fibPrev);
    }
    return $fib;
}
Task: Fibonacci sequence






PHP: function fibIter($n) {
    if ($n < 2) {
        return $n;
    }
    $fibPrev = 0;
    $fib = 1;
    foreach (range(1, $n-1) as $i) {
        list($fibPrev, $fib) = array($fib, $fib + $fibPrev);
    }
    return $fib;
}


Python: from math import *

def analytic_fibonacci(n):
  sqrt_5 = sqrt(5);
  p = (1 + sqrt_5) / 2;
  q = 1/p;
  return int( (p**n + q**n) / sqrt_5 + 0.5 )

for i in range(1,31):
  print analytic_fibonacci(i),
Task: Fibonacci sequence






PHP: function fibIter($n) {
    if ($n < 2) {
        return $n;
    }
    $fibPrev = 0;
    $fib = 1;
    foreach (range(1, $n-1) as $i) {
        list($fibPrev, $fib) = array($fib, $fib + $fibPrev);
    }
    return $fib;
}



VB: Public Function Fib(ByVal n As Integer) As Variant
    Dim fib0 As Variant, fib1 As Variant, sum As Variant
    Dim i As Integer
    fib0 = 0
    fib1 = 1
    For i = 1 To n
        sum = fib0 + fib1
        fib0 = fib1
        fib1 = sum
    Next i
    Fib = fib0
End Function
Task: Loops_While

C: int i = 1024;
while(i > 0) {
  printf("%d\n", i);
  i /= 2;
}



C#: int i = 1024;
while(i > 0){
   System.Console.WriteLine(i);
   i /= 2;
}
Task: Loops_While

C: int i = 1024;
while(i > 0) {
  printf("%d\n", i);
  i /= 2;
}


C++: int i = 1024;
while(i > 0){
  std::cout << i << std::endl;
  i /= 2;
}
Task: Loops_While

C: int i = 1024;
while(i > 0) {
  printf("%d\n", i);
  i /= 2;
}




Go: i := 1024
for i > 0 {
  fmt.Printf("%d\n", i)
  i /= 2
}
Task: Loops_While

C: int i = 1024;
while(i > 0) {
  printf("%d\n", i);
  i /= 2;
}








VB: Public Sub LoopsWhile()
    Dim value As Integer
    value = 1024
    Do While value > 0
        Debug.Print value
        value = value / 2
    Loop
End Sub
Task: Loops_While


C++: int i = 1024;
while(i > 0){
  std::cout << i << std::endl;
  i /= 2;
}


C#: int i = 1024;
while(i > 0){
   System.Console.WriteLine(i);
   i /= 2;
}
Task: Loops_While


C++: int i = 1024;
while(i > 0){
  std::cout << i << std::endl;
  i /= 2;
}



Go: i := 1024
for i > 0 {
  fmt.Printf("%d\n", i)
  i /= 2
}
Task: Loops_While


C++: int i = 1024;
while(i > 0){
  std::cout << i << std::endl;
  i /= 2;
}




Java: int i = 1024;
while(i > 0){
   System.out.println(i);
   i >>= 1; 
}
Task: Loops_While


C++: int i = 1024;
while(i > 0){
  std::cout << i << std::endl;
  i /= 2;
}






Python: n = 1024
while n > 0:
    print n
    n //= 2
Task: Loops_While


C++: int i = 1024;
while(i > 0){
  std::cout << i << std::endl;
  i /= 2;
}







VB: Public Sub LoopsWhile()
    Dim value As Integer
    value = 1024
    Do While value > 0
        Debug.Print value
        value = value / 2
    Loop
End Sub
Task: Loops_While



C#: int i = 1024;
while(i > 0){
   System.Console.WriteLine(i);
   i /= 2;
}


Go: i := 1024
for i > 0 {
  fmt.Printf("%d\n", i)
  i /= 2
}
Task: Loops_While



C#: int i = 1024;
while(i > 0){
   System.Console.WriteLine(i);
   i /= 2;
}



Java: int i = 1024;
while(i > 0){
   System.out.println(i);
   i >>= 1; 
}
Task: Loops_While



C#: int i = 1024;
while(i > 0){
   System.Console.WriteLine(i);
   i /= 2;
}






VB: Public Sub LoopsWhile()
    Dim value As Integer
    value = 1024
    Do While value > 0
        Debug.Print value
        value = value / 2
    Loop
End Sub
Task: Loops_While




Go: i := 1024
for i > 0 {
  fmt.Printf("%d\n", i)
  i /= 2
}




Python: n = 1024
while n > 0:
    print n
    n //= 2
Task: Loops_While




Go: i := 1024
for i > 0 {
  fmt.Printf("%d\n", i)
  i /= 2
}





VB: Public Sub LoopsWhile()
    Dim value As Integer
    value = 1024
    Do While value > 0
        Debug.Print value
        value = value / 2
    Loop
End Sub
Task: Loops_While







Python: n = 1024
while n > 0:
    print n
    n //= 2


VB: Public Sub LoopsWhile()
    Dim value As Integer
    value = 1024
    Do While value > 0
        Debug.Print value
        value = value / 2
    Loop
End Sub
Task: Loops_While




Go: i := 1024
for i > 0 {
  fmt.Printf("%d\n", i)
  i /= 2
}


Java: int i = 1024;
while(i > 0){
   System.out.println(i);
   i >>= 1; 
}
Task: Loops_While





Java: int i = 1024;
while(i > 0){
   System.out.println(i);
   i >>= 1; 
}



Python: n = 1024
while n > 0:
    print n
    n //= 2
Task: Loops_While





Java: int i = 1024;
while(i > 0){
   System.out.println(i);
   i >>= 1; 
}




VB: Public Sub LoopsWhile()
    Dim value As Integer
    value = 1024
    Do While value > 0
        Debug.Print value
        value = value / 2
    Loop
End Sub
Task: Loops_While

C: int i = 1024;
while(i > 0) {
  printf("%d\n", i);
  i /= 2;
}





Java: int i = 1024;
while(i > 0){
   System.out.println(i);
   i >>= 1; 
}
Task: Loops_While

C: int i = 1024;
while(i > 0) {
  printf("%d\n", i);
  i /= 2;
}







Python: n = 1024
while n > 0:
    print n
    n //= 2
Task: Loops_While



C#: int i = 1024;
while(i > 0){
   System.Console.WriteLine(i);
   i /= 2;
}





Python: n = 1024
while n > 0:
    print n
    n //= 2
Task: Loops_While

C: int i = 1024;
while(i > 0) {
  printf("%d\n", i);
  i /= 2;
}






PHP: $i = 1024;
while ($i > 0) {
   echo "$i\n";
   $i >>= 1;
}
Task: Loops_While



C#: int i = 1024;
while(i > 0){
   System.Console.WriteLine(i);
   i /= 2;
}




PHP: $i = 1024;
while ($i > 0) {
   echo "$i\n";
   $i >>= 1;
}
Task: Loops_While


C++: int i = 1024;
while(i > 0){
  std::cout << i << std::endl;
  i /= 2;
}





PHP: $i = 1024;
while ($i > 0) {
   echo "$i\n";
   $i >>= 1;
}
Task: Loops_While




Go: i := 1024
for i > 0 {
  fmt.Printf("%d\n", i)
  i /= 2
}



PHP: $i = 1024;
while ($i > 0) {
   echo "$i\n";
   $i >>= 1;
}
Task: Loops_While





Java: int i = 1024;
while(i > 0){
   System.out.println(i);
   i >>= 1; 
}


PHP: $i = 1024;
while ($i > 0) {
   echo "$i\n";
   $i >>= 1;
}
Task: Loops_While






PHP: $i = 1024;
while ($i > 0) {
   echo "$i\n";
   $i >>= 1;
}


Python: n = 1024
while n > 0:
    print n
    n //= 2
Task: Loops_While






PHP: $i = 1024;
while ($i > 0) {
   echo "$i\n";
   $i >>= 1;
}



VB: Public Sub LoopsWhile()
    Dim value As Integer
    value = 1024
    Do While value > 0
        Debug.Print value
        value = value / 2
    Loop
End Sub
Task: Sum of a series

C: #include <stdio.h>

double Invsqr(double n)
{
	return 1 / (n*n);
}

int main (int argc, char *argv[])
{
	int i, start = 1, end = 1000;
	double sum = 0.0;
	
	for( i = start; i <= end; i++)
		sum += Invsqr((double)i);           
	
	printf("%16.14f\n", sum);
	
	return 0;
}



C#: class Program
{
    static void Main(string[] args)
    {
        

        List<double> myList = new List<double>();
        for (double i = 1; i < 1001; i++)
        {
            myList.Add(i);
        }
        

        var sum = myList.Sum(x => 1/(x*x));

        Console.WriteLine(sum);
        Console.ReadLine();
    }
}
Task: Sum of a series

C: #include <stdio.h>

double Invsqr(double n)
{
	return 1 / (n*n);
}

int main (int argc, char *argv[])
{
	int i, start = 1, end = 1000;
	double sum = 0.0;
	
	for( i = start; i <= end; i++)
		sum += Invsqr((double)i);           
	
	printf("%16.14f\n", sum);
	
	return 0;
}


C++: #include <iostream>

double f(double x);

int main()
{
    unsigned int start = 1;
    unsigned int end = 1000;
    double sum = 0;

    for( unsigned int x = start; x <= end; ++x )
    {
        sum += f(x);
    }
    std::cout << "Sum of f(x) from " << start << " to " << end << " is " << sum << std::endl;
    return 0;
}


double f(double x)
{
    return ( 1.0 / ( x * x ) );
}
Task: Sum of a series

C: #include <stdio.h>

double Invsqr(double n)
{
	return 1 / (n*n);
}

int main (int argc, char *argv[])
{
	int i, start = 1, end = 1000;
	double sum = 0.0;
	
	for( i = start; i <= end; i++)
		sum += Invsqr((double)i);           
	
	printf("%16.14f\n", sum);
	
	return 0;
}





Java: public class Sum{
    public static double f(double x){
       return 1/(x*x);
    }
 
    public static void main(String[] args){
       double start = 1;
       double end = 1000;
       double sum = 0;
 
       for(double x = start;x <= end;x++) sum += f(x);
 
       System.out.println("Sum of f(x) from " + start + " to " + end +" is " + sum);
    }
}
Task: Sum of a series

C: #include <stdio.h>

double Invsqr(double n)
{
	return 1 / (n*n);
}

int main (int argc, char *argv[])
{
	int i, start = 1, end = 1000;
	double sum = 0.0;
	
	for( i = start; i <= end; i++)
		sum += Invsqr((double)i);           
	
	printf("%16.14f\n", sum);
	
	return 0;
}







Python: print ( sum(1.0 / (x * x) for x in range(1, 1001)) )