diff --git a/README.md b/README.md index 4ca980846..c80e8a58b 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,42 @@ the hard work. # How? -```bash -python c2go.py tests/hello-world.c +Let's use +[prime.c](https://github.com/elliotchance/c2go/blob/master/tests/prime.c): + +```c +#include + +int main() +{ + int n, c; + + printf("Enter a number\n"); + scanf("%d", &n); + + if ( n == 2 ) + printf("Prime number.\n"); + else + { + for ( c = 2 ; c <= n - 1 ; c++ ) + { + if ( n % c == 0 ) + break; + } + if ( c != n ) + printf("Not prime.\n"); + else + printf("Prime number.\n"); + } + return 0; +} ``` +```bash +python c2go.py tests/prime.c ``` + +```go package main import ( @@ -22,7 +53,24 @@ import ( // ... lots of system types in Go removed for brevity. func main() { - fmt.Printf("Hello World\n") + var n int + var c int + fmt.Printf("Enter a number\n") + fmt.Scanf("%d", &n) + if n == 2 { + fmt.Printf("Prime number.\n") + } else { + for c = 2; c <= n - 1; c += 1 { + if n % c == 0 { + break + } + } + if c != n { + fmt.Printf("Not prime.\n") + } else { + fmt.Printf("Prime number.\n") + } + } return } ```