kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Fork
C: #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <err.h>

int main()
{
	pid_t pid;

	if (!(pid = fork())) {
		usleep(10000);
		printf("\tchild process: done\n");
	} else if (pid < 0) {
		err(1, "fork error");
	} else {
		printf("waiting for child %d...\n", (int)pid);
		printf("child %d finished\n", (int)wait(0));
	}

	return 0;
}

Go: package main

import (
    "fmt"
    "os"
)

func main() {
    fmt.Printf("PID: %v\n", os.Getpid())
    if len(os.Args) < 2 {
        fmt.Println("Done.")
        return
    }
    cp, err := os.StartProcess(os.Args[0], nil,
        &os.ProcAttr{Files: []*os.File{nil, os.Stdout}},
    )
    if err != nil {
        fmt.Println(err)
    }
    
    
    fmt.Printf("Child's PID: %v\n", cp.Pid)
    if _, err = cp.Wait(); err != nil {
        fmt.Println(err)
    }
}
Task: Fork
C: #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <err.h>

int main()
{
	pid_t pid;

	if (!(pid = fork())) {
		usleep(10000);
		printf("\tchild process: done\n");
	} else if (pid < 0) {
		err(1, "fork error");
	} else {
		printf("waiting for child %d...\n", (int)pid);
		printf("child %d finished\n", (int)wait(0));
	}

	return 0;
}

Java: import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class RFork {

  public static void main(String[] args) {
    ProcessBuilder pb;
    Process pp;
    List<String> command;
    Map<String, String> env;
    BufferedReader ir;
    String currentuser;
    String line;
    try {
      command = Arrays.asList("");
      pb = new ProcessBuilder(command);
      env = pb.environment();
      currentuser = env.get("USER");
      command = Arrays.asList("ps", "-f", "-U", currentuser);
      pb.command(command);
      pp = pb.start();
      ir = new BufferedReader(new InputStreamReader(pp.getInputStream()));
      line = "Output of running " + command.toString() + " is:";
      do {
        System.out.println(line);
      } while ((line = ir.readLine()) != null);
    }
    catch (IOException iox) {
      iox.printStackTrace();
    }

    return;
  }
}
Task: Fork
Go: package main

import (
    "fmt"
    "os"
)

func main() {
    fmt.Printf("PID: %v\n", os.Getpid())
    if len(os.Args) < 2 {
        fmt.Println("Done.")
        return
    }
    cp, err := os.StartProcess(os.Args[0], nil,
        &os.ProcAttr{Files: []*os.File{nil, os.Stdout}},
    )
    if err != nil {
        fmt.Println(err)
    }
    
    
    fmt.Printf("Child's PID: %v\n", cp.Pid)
    if _, err = cp.Wait(); err != nil {
        fmt.Println(err)
    }
}

Java: import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class RFork {

  public static void main(String[] args) {
    ProcessBuilder pb;
    Process pp;
    List<String> command;
    Map<String, String> env;
    BufferedReader ir;
    String currentuser;
    String line;
    try {
      command = Arrays.asList("");
      pb = new ProcessBuilder(command);
      env = pb.environment();
      currentuser = env.get("USER");
      command = Arrays.asList("ps", "-f", "-U", currentuser);
      pb.command(command);
      pp = pb.start();
      ir = new BufferedReader(new InputStreamReader(pp.getInputStream()));
      line = "Output of running " + command.toString() + " is:";
      do {
        System.out.println(line);
      } while ((line = ir.readLine()) != null);
    }
    catch (IOException iox) {
      iox.printStackTrace();
    }

    return;
  }
}
Task: Fork
Go: package main

import (
    "fmt"
    "os"
)

func main() {
    fmt.Printf("PID: %v\n", os.Getpid())
    if len(os.Args) < 2 {
        fmt.Println("Done.")
        return
    }
    cp, err := os.StartProcess(os.Args[0], nil,
        &os.ProcAttr{Files: []*os.File{nil, os.Stdout}},
    )
    if err != nil {
        fmt.Println(err)
    }
    
    
    fmt.Printf("Child's PID: %v\n", cp.Pid)
    if _, err = cp.Wait(); err != nil {
        fmt.Println(err)
    }
}

VB: Module Module1

    Sub Fork()
        Console.WriteLine("Spawned Thread")
    End Sub

    Sub Main()
        Dim t As New System.Threading.Thread(New Threading.ThreadStart(AddressOf Fork))
        t.Start()

        Console.WriteLine("Main Thread")
        t.Join()
    End Sub

End Module
Task: Fork
C++: #include<iostream>
#include<unistd.h>

int main()
{
  pid_t pid = fork();

  if (pid == 0)
  {
    std::cout << "This is the new process\n";
  }
  else if (pid > 0)
  {
    std::cout << "This is the original process\n";
  }
  else
  {
    std::cerr << "ERROR: Something went wrong\n";
  }

  return 0;
}

Java: import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class RFork {

  public static void main(String[] args) {
    ProcessBuilder pb;
    Process pp;
    List<String> command;
    Map<String, String> env;
    BufferedReader ir;
    String currentuser;
    String line;
    try {
      command = Arrays.asList("");
      pb = new ProcessBuilder(command);
      env = pb.environment();
      currentuser = env.get("USER");
      command = Arrays.asList("ps", "-f", "-U", currentuser);
      pb.command(command);
      pp = pb.start();
      ir = new BufferedReader(new InputStreamReader(pp.getInputStream()));
      line = "Output of running " + command.toString() + " is:";
      do {
        System.out.println(line);
      } while ((line = ir.readLine()) != null);
    }
    catch (IOException iox) {
      iox.printStackTrace();
    }

    return;
  }
}
Task: Fork
Java: import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class RFork {

  public static void main(String[] args) {
    ProcessBuilder pb;
    Process pp;
    List<String> command;
    Map<String, String> env;
    BufferedReader ir;
    String currentuser;
    String line;
    try {
      command = Arrays.asList("");
      pb = new ProcessBuilder(command);
      env = pb.environment();
      currentuser = env.get("USER");
      command = Arrays.asList("ps", "-f", "-U", currentuser);
      pb.command(command);
      pp = pb.start();
      ir = new BufferedReader(new InputStreamReader(pp.getInputStream()));
      line = "Output of running " + command.toString() + " is:";
      do {
        System.out.println(line);
      } while ((line = ir.readLine()) != null);
    }
    catch (IOException iox) {
      iox.printStackTrace();
    }

    return;
  }
}

Python: import os

pid = os.fork()
if pid > 0:
 
else:
Task: Fork
Java: import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class RFork {

  public static void main(String[] args) {
    ProcessBuilder pb;
    Process pp;
    List<String> command;
    Map<String, String> env;
    BufferedReader ir;
    String currentuser;
    String line;
    try {
      command = Arrays.asList("");
      pb = new ProcessBuilder(command);
      env = pb.environment();
      currentuser = env.get("USER");
      command = Arrays.asList("ps", "-f", "-U", currentuser);
      pb.command(command);
      pp = pb.start();
      ir = new BufferedReader(new InputStreamReader(pp.getInputStream()));
      line = "Output of running " + command.toString() + " is:";
      do {
        System.out.println(line);
      } while ((line = ir.readLine()) != null);
    }
    catch (IOException iox) {
      iox.printStackTrace();
    }

    return;
  }
}

VB: Module Module1

    Sub Fork()
        Console.WriteLine("Spawned Thread")
    End Sub

    Sub Main()
        Dim t As New System.Threading.Thread(New Threading.ThreadStart(AddressOf Fork))
        t.Start()

        Console.WriteLine("Main Thread")
        t.Join()
    End Sub

End Module
Task: Fork
C: #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <err.h>

int main()
{
	pid_t pid;

	if (!(pid = fork())) {
		usleep(10000);
		printf("\tchild process: done\n");
	} else if (pid < 0) {
		err(1, "fork error");
	} else {
		printf("waiting for child %d...\n", (int)pid);
		printf("child %d finished\n", (int)wait(0));
	}

	return 0;
}

PHP: <?php
$pid = pcntl_fork();
if ($pid == 0)
  echo "This is the new process\n";
else if ($pid > 0)
  echo "This is the original process\n";
else
  echo "ERROR: Something went wrong\n";
?>
Task: Fork
C++: #include<iostream>
#include<unistd.h>

int main()
{
  pid_t pid = fork();

  if (pid == 0)
  {
    std::cout << "This is the new process\n";
  }
  else if (pid > 0)
  {
    std::cout << "This is the original process\n";
  }
  else
  {
    std::cerr << "ERROR: Something went wrong\n";
  }

  return 0;
}

PHP: <?php
$pid = pcntl_fork();
if ($pid == 0)
  echo "This is the new process\n";
else if ($pid > 0)
  echo "This is the original process\n";
else
  echo "ERROR: Something went wrong\n";
?>
Task: Fork
Go: package main

import (
    "fmt"
    "os"
)

func main() {
    fmt.Printf("PID: %v\n", os.Getpid())
    if len(os.Args) < 2 {
        fmt.Println("Done.")
        return
    }
    cp, err := os.StartProcess(os.Args[0], nil,
        &os.ProcAttr{Files: []*os.File{nil, os.Stdout}},
    )
    if err != nil {
        fmt.Println(err)
    }
    
    
    fmt.Printf("Child's PID: %v\n", cp.Pid)
    if _, err = cp.Wait(); err != nil {
        fmt.Println(err)
    }
}

PHP: <?php
$pid = pcntl_fork();
if ($pid == 0)
  echo "This is the new process\n";
else if ($pid > 0)
  echo "This is the original process\n";
else
  echo "ERROR: Something went wrong\n";
?>
Task: Fork
Java: import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class RFork {

  public static void main(String[] args) {
    ProcessBuilder pb;
    Process pp;
    List<String> command;
    Map<String, String> env;
    BufferedReader ir;
    String currentuser;
    String line;
    try {
      command = Arrays.asList("");
      pb = new ProcessBuilder(command);
      env = pb.environment();
      currentuser = env.get("USER");
      command = Arrays.asList("ps", "-f", "-U", currentuser);
      pb.command(command);
      pp = pb.start();
      ir = new BufferedReader(new InputStreamReader(pp.getInputStream()));
      line = "Output of running " + command.toString() + " is:";
      do {
        System.out.println(line);
      } while ((line = ir.readLine()) != null);
    }
    catch (IOException iox) {
      iox.printStackTrace();
    }

    return;
  }
}

PHP: <?php
$pid = pcntl_fork();
if ($pid == 0)
  echo "This is the new process\n";
else if ($pid > 0)
  echo "This is the original process\n";
else
  echo "ERROR: Something went wrong\n";
?>
Task: Fork
Python: import os

pid = os.fork()
if pid > 0:
 
else:
 

PHP: <?php
$pid = pcntl_fork();
if ($pid == 0)
  echo "This is the new process\n";
else if ($pid > 0)
  echo "This is the original process\n";
else
  echo "ERROR: Something went wrong\n";
?>
Task: Fork
VB: Module Module1

    Sub Fork()
        Console.WriteLine("Spawned Thread")
    End Sub

    Sub Main()
        Dim t As New System.Threading.Thread(New Threading.ThreadStart(AddressOf Fork))
        t.Start()

        Console.WriteLine("Main Thread")
        t.Join()
    End Sub

End Module

PHP: <?php
$pid = pcntl_fork();
if ($pid == 0)
  echo "This is the new process\n";
else if ($pid > 0)
  echo "This is the original process\n";
else
  echo "ERROR: Something went wrong\n";
?>
Task: Roots of a function
C: #include <math.h>
#include <stdio.h>

double f(double x)
{
    return x*x*x-3.0*x*x +2.0*x;
}

double secant( double xA, double xB, double(*f)(double) )
{
    double e = 1.0e-12;
    double fA, fB;
    double d;
    int i;
    int limit = 50;

    fA=(*f)(xA);
    for (i=0; i<limit; i++) {
        fB=(*f)(xB);
        d = (xB - xA) / (fB - fA) * fB;
        if (fabs(d) < e) 
            break;
        xA = xB;
        fA = fB;
        xB -= d;
    }
    if (i==limit) {
        printf("Function is not converging near (%7.4f,%7.4f).\n", xA,xB);
        return -99.0;
    }
    return xB;
}

int main(int argc, char *argv[])
{
    double step = 1.0e-2;
    double e = 1.0e-12;
    double x = -1.032;		
    double xx, value;

    int s = (f(x)> 0.0);

    while (x < 3.0) {
        value = f(x);
        if (fabs(value) < e) {
            printf("Root found at x= %12.9f\n", x);
            s = (f(x+.0001)>0.0);
        }
        else if ((value > 0.0) != s) {
            xx = secant(x-step, x,&f);
            if (xx != -99.0)   
                printf("Root found at x= %12.9f\n", xx);
            else
                printf("Root found near x= %7.4f\n", x);
            s = (f(x+.0001)>0.0);
        }
        x += step;
    }
    return 0;
}

C#: using System;

class Program
{
    public static void Main(string[] args)
    {
        Func<double, double> f = x => { return x * x * x - 3 * x * x + 2 * x; };

        double step = 0.001; 
        double start = -1;
        double stop = 3;
        double value = f(start);
        int sign = (value > 0) ? 1 : 0;
 
        
        if (value == 0)
            Console.WriteLine("Root found at {0}", start);

        for (var x = start + step; x <= stop; x += step)
        {
            value = f(x);
 
            if (((value > 0) ? 1 : 0) != sign)
                
                Console.WriteLine("Root found near {0}", x);
            else if (value == 0)
                
                Console.WriteLine("Root found at {0}", x);
 
            
            sign = (value > 0) ? 1 : 0;
        }
    }
}
Task: Roots of a function
C: #include <math.h>
#include <stdio.h>

double f(double x)
{
    return x*x*x-3.0*x*x +2.0*x;
}

double secant( double xA, double xB, double(*f)(double) )
{
    double e = 1.0e-12;
    double fA, fB;
    double d;
    int i;
    int limit = 50;

    fA=(*f)(xA);
    for (i=0; i<limit; i++) {
        fB=(*f)(xB);
        d = (xB - xA) / (fB - fA) * fB;
        if (fabs(d) < e) 
            break;
        xA = xB;
        fA = fB;
        xB -= d;
    }
    if (i==limit) {
        printf("Function is not converging near (%7.4f,%7.4f).\n", xA,xB);
        return -99.0;
    }
    return xB;
}

int main(int argc, char *argv[])
{
    double step = 1.0e-2;
    double e = 1.0e-12;
    double x = -1.032;		
    double xx, value;

    int s = (f(x)> 0.0);

    while (x < 3.0) {
        value = f(x);
        if (fabs(value) < e) {
            printf("Root found at x= %12.9f\n", x);
            s = (f(x+.0001)>0.0);
        }
        else if ((value > 0.0) != s) {
            xx = secant(x-step, x,&f);
            if (xx != -99.0)   
                printf("Root found at x= %12.9f\n", xx);
            else
                printf("Root found near x= %7.4f\n", x);
            s = (f(x+.0001)>0.0);
        }
        x += step;
    }
    return 0;
}

C++: #include <iostream>

double f(double x)
{
	return (x*x*x - 3*x*x + 2*x);
}

int main()
{
	double step = 0.001; 
	double start = -1;
	double stop = 3;
	double value = f(start);
	double sign = (value > 0);
	
	
	if ( 0 == value )
		std::cout << "Root found at " << start << std::endl;

	for(	double x = start + step;
			x <= stop;
			x += step )
	{
		value = f(x);
		
		if ( ( value > 0 ) != sign )
			
			std::cout << "Root found near " << x << std::endl;
		else if ( 0 == value )
			
			std::cout << "Root found at " << x << std::endl;
		
		
		sign = ( value > 0 );
	}
}
Task: Roots of a function
C: #include <math.h>
#include <stdio.h>

double f(double x)
{
    return x*x*x-3.0*x*x +2.0*x;
}

double secant( double xA, double xB, double(*f)(double) )
{
    double e = 1.0e-12;
    double fA, fB;
    double d;
    int i;
    int limit = 50;

    fA=(*f)(xA);
    for (i=0; i<limit; i++) {
        fB=(*f)(xB);
        d = (xB - xA) / (fB - fA) * fB;
        if (fabs(d) < e) 
            break;
        xA = xB;
        fA = fB;
        xB -= d;
    }
    if (i==limit) {
        printf("Function is not converging near (%7.4f,%7.4f).\n", xA,xB);
        return -99.0;
    }
    return xB;
}

int main(int argc, char *argv[])
{
    double step = 1.0e-2;
    double e = 1.0e-12;
    double x = -1.032;		
    double xx, value;

    int s = (f(x)> 0.0);

    while (x < 3.0) {
        value = f(x);
        if (fabs(value) < e) {
            printf("Root found at x= %12.9f\n", x);
            s = (f(x+.0001)>0.0);
        }
        else if ((value > 0.0) != s) {
            xx = secant(x-step, x,&f);
            if (xx != -99.0)   
                printf("Root found at x= %12.9f\n", xx);
            else
                printf("Root found near x= %7.4f\n", x);
            s = (f(x+.0001)>0.0);
        }
        x += step;
    }
    return 0;
}

Go: package main

import (
	"fmt"
	"math"
)

func main() {
	example := func(x float64) float64 { return x*x*x - 3*x*x + 2*x }
	findroots(example, -.5, 2.6, 1)
}

func findroots(f func(float64) float64, lower, upper, step float64) {
	for x0, x1 := lower, lower+step; x0 < upper; x0, x1 = x1, x1+step {
		x1 = math.Min(x1, upper)
		r, status := secant(f, x0, x1)
		if status != "" && r >= x0 && r < x1 {
			fmt.Printf("  %6.3f %s\n", r, status)
		}
	}
}

func secant(f func(float64) float64, x0, x1 float64) (float64, string) {
	var f0 float64
	f1 := f(x0)
	for i := 0; i < 100; i++ {
		f0, f1 = f1, f(x1)
		switch {
		case f1 == 0:
			return x1, "exact"
		case math.Abs(x1-x0) < 1e-6:
			return x1, "approximate"
		}
		x0, x1 = x1, x1-f1*(x1-x0)/(f1-f0)
	}
	return 0, ""
}
Task: Roots of a function
C#: using System;

class Program
{
    public static void Main(string[] args)
    {
        Func<double, double> f = x => { return x * x * x - 3 * x * x + 2 * x; };

        double step = 0.001; 
        double start = -1;
        double stop = 3;
        double value = f(start);
        int sign = (value > 0) ? 1 : 0;
 
        
        if (value == 0)
            Console.WriteLine("Root found at {0}", start);

        for (var x = start + step; x <= stop; x += step)
        {
            value = f(x);
 
            if (((value > 0) ? 1 : 0) != sign)
                
                Console.WriteLine("Root found near {0}", x);
            else if (value == 0)
                
                Console.WriteLine("Root found at {0}", x);
 
            
            sign = (value > 0) ? 1 : 0;
        }
    }
}

C++: #include <iostream>

double f(double x)
{
	return (x*x*x - 3*x*x + 2*x);
}

int main()
{
	double step = 0.001; 
	double start = -1;
	double stop = 3;
	double value = f(start);
	double sign = (value > 0);
	
	
	if ( 0 == value )
		std::cout << "Root found at " << start << std::endl;

	for(	double x = start + step;
			x <= stop;
			x += step )
	{
		value = f(x);
		
		if ( ( value > 0 ) != sign )
			
			std::cout << "Root found near " << x << std::endl;
		else if ( 0 == value )
			
			std::cout << "Root found at " << x << std::endl;
		
		
		sign = ( value > 0 );
	}
}
Task: Roots of a function
C#: using System;

class Program
{
    public static void Main(string[] args)
    {
        Func<double, double> f = x => { return x * x * x - 3 * x * x + 2 * x; };

        double step = 0.001; 
        double start = -1;
        double stop = 3;
        double value = f(start);
        int sign = (value > 0) ? 1 : 0;
 
        
        if (value == 0)
            Console.WriteLine("Root found at {0}", start);

        for (var x = start + step; x <= stop; x += step)
        {
            value = f(x);
 
            if (((value > 0) ? 1 : 0) != sign)
                
                Console.WriteLine("Root found near {0}", x);
            else if (value == 0)
                
                Console.WriteLine("Root found at {0}", x);
 
            
            sign = (value > 0) ? 1 : 0;
        }
    }
}

Go: package main

import (
	"fmt"
	"math"
)

func main() {
	example := func(x float64) float64 { return x*x*x - 3*x*x + 2*x }
	findroots(example, -.5, 2.6, 1)
}

func findroots(f func(float64) float64, lower, upper, step float64) {
	for x0, x1 := lower, lower+step; x0 < upper; x0, x1 = x1, x1+step {
		x1 = math.Min(x1, upper)
		r, status := secant(f, x0, x1)
		if status != "" && r >= x0 && r < x1 {
			fmt.Printf("  %6.3f %s\n", r, status)
		}
	}
}

func secant(f func(float64) float64, x0, x1 float64) (float64, string) {
	var f0 float64
	f1 := f(x0)
	for i := 0; i < 100; i++ {
		f0, f1 = f1, f(x1)
		switch {
		case f1 == 0:
			return x1, "exact"
		case math.Abs(x1-x0) < 1e-6:
			return x1, "approximate"
		}
		x0, x1 = x1, x1-f1*(x1-x0)/(f1-f0)
	}
	return 0, ""
}
Task: Roots of a function
C#: using System;

class Program
{
    public static void Main(string[] args)
    {
        Func<double, double> f = x => { return x * x * x - 3 * x * x + 2 * x; };

        double step = 0.001; 
        double start = -1;
        double stop = 3;
        double value = f(start);
        int sign = (value > 0) ? 1 : 0;
 
        
        if (value == 0)
            Console.WriteLine("Root found at {0}", start);

        for (var x = start + step; x <= stop; x += step)
        {
            value = f(x);
 
            if (((value > 0) ? 1 : 0) != sign)
                
                Console.WriteLine("Root found near {0}", x);
            else if (value == 0)
                
                Console.WriteLine("Root found at {0}", x);
 
            
            sign = (value > 0) ? 1 : 0;
        }
    }
}

Java: public class Roots {
    public interface Function {
	public double f(double x);
    }

    private static int sign(double x) {
	return (x < 0.0) ? -1 : (x > 0.0) ? 1 : 0;
    }

    public static void printRoots(Function f, double lowerBound,
				  double upperBound, double step) {
	double x = lowerBound, ox = x;
	double y = f.f(x), oy = y;
	int s = sign(y), os = s;

	for (; x <= upperBound ; x += step) {
	    s = sign(y = f.f(x));
	    if (s == 0) {
		System.out.println(x);
	    } else if (s != os) {
		double dx = x - ox;
		double dy = y - oy;
		double cx = x - dx * (y / dy);
		System.out.println("~" + cx);
	    }
	    ox = x; oy = y; os = s;
	}
    }

    public static void main(String[] args) {
	Function poly = new Function () {
	    public double f(double x) {
		return x*x*x - 3*x*x + 2*x;
	    }
	};
	printRoots(poly, -1.0, 4, 0.002);
    }
}
Task: Roots of a function
C#: using System;

class Program
{
    public static void Main(string[] args)
    {
        Func<double, double> f = x => { return x * x * x - 3 * x * x + 2 * x; };

        double step = 0.001; 
        double start = -1;
        double stop = 3;
        double value = f(start);
        int sign = (value > 0) ? 1 : 0;
 
        
        if (value == 0)
            Console.WriteLine("Root found at {0}", start);

        for (var x = start + step; x <= stop; x += step)
        {
            value = f(x);
 
            if (((value > 0) ? 1 : 0) != sign)
                
                Console.WriteLine("Root found near {0}", x);
            else if (value == 0)
                
                Console.WriteLine("Root found at {0}", x);
 
            
            sign = (value > 0) ? 1 : 0;
        }
    }
}

Python: f = lambda x: x * x * x - 3 * x * x + 2 * x

step = 0.001 
start = -1
stop = 3

sign = f(start) > 0

x = start
while x <= stop:
    value = f(x)

    if value == 0:
        
        print "Root found at", x
    elif (value > 0) != sign:
        
        print "Root found near", x

    
    sign = value > 0

    x += step