This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup: CLI arguments for C, CPP, Go, Ruby
Signed-off-by: Richard Zak <[email protected]>
- Loading branch information
Showing
6 changed files
with
88 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ Zig/*/zig-out/ | |
.idea/ | ||
.vscode/ | ||
result | ||
*.wasm | ||
a.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
// Simple Program to calculate Fibonacci Sequence of an integer input | ||
#include <iostream> | ||
#include <cstdlib> | ||
using namespace std; | ||
|
||
#define DEFAULT_N 10 | ||
|
||
int FibonacciSequence(int num) { | ||
if(num <= 1) { | ||
return num ; | ||
} | ||
return FibonacciSequence(num-1) + FibonacciSequence(num-2); | ||
} | ||
int main(){ | ||
cout << "Enter the Number" << endl; | ||
int n ; | ||
cin >> n ; | ||
|
||
cout << "Fibonacci Sequence term at " << n << " " << "is " << FibonacciSequence(n) << endl; | ||
int main(int argc, char* argv[]){ | ||
int n = DEFAULT_N; | ||
if (argc > 1) { | ||
n = atoi(argv[1]); | ||
} else { | ||
cout << "Which Fibonacci index to find? "; | ||
cout.flush(); | ||
cin >> n; | ||
} | ||
|
||
if (n < -1) { | ||
n = DEFAULT_N; | ||
} | ||
|
||
cout << "Fibonacci sequence number at index " << n << " is " << FibonacciSequence(n) << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,30 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#define DEFAULT_N 10 | ||
|
||
int FibonacciSequence(int num) { | ||
if(num <= 1) { | ||
return num ; | ||
} | ||
return FibonacciSequence(num-1) + FibonacciSequence(num-2); | ||
} | ||
int main(){ | ||
printf("Enter the Number\n"); | ||
int n ; | ||
scanf("%d",&n); | ||
|
||
printf("Fibonacci Sequence term at %d is %d " , n , FibonacciSequence(n)); | ||
int main(int argc, char* argv[]){ | ||
int n = DEFAULT_N; | ||
if (argc > 1) { | ||
n = atoi(argv[1]); | ||
} else { | ||
printf("Which Fibonacci index to find? "); | ||
int matched = scanf("%d", &n); | ||
if (matched < 1) { | ||
n = DEFAULT_N; | ||
} | ||
} | ||
|
||
if (n < -1) { | ||
n = DEFAULT_N; | ||
} | ||
|
||
printf("Fibonacci sequence number at index %d is %d" , n , FibonacciSequence(n)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/enarx/codex/Go/fibonacci | ||
|
||
go 1.17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,35 @@ | ||
// Simple Program to calculate fibonacci of input | ||
|
||
package main | ||
|
||
import "fmt" | ||
func FibonacciRecursion(n int) int { | ||
import ( | ||
"fmt" | ||
"strconv" | ||
"os" | ||
) | ||
|
||
const DEFAULT_N int = 10 | ||
|
||
func FibonacciSequence(n int) int { | ||
if n <= 1 { | ||
return n | ||
} | ||
return FibonacciRecursion(n-1) + FibonacciRecursion(n-2) | ||
return FibonacciSequence(n-1) + FibonacciSequence(n-2) | ||
} | ||
|
||
func main(){ | ||
fmt.Print("Enter number : ") | ||
var n int | ||
fmt.Scanln(&n) | ||
n := DEFAULT_N | ||
|
||
if len(os.Args) > 1 { | ||
n, _ = strconv.Atoi(os.Args[1]) | ||
} else { | ||
var input string | ||
fmt.Print("Which Fibonacci index to find? ") | ||
fmt.Scanln(&input) | ||
n, _ = strconv.Atoi(input) | ||
} | ||
|
||
if n < -1 { | ||
n = DEFAULT_N | ||
} | ||
|
||
fmt.Println("Fibonacci of", n , "is", FibonacciRecursion(n)); | ||
fmt.Printf("Fibonacci sequence number at index %d is %d" , n , FibonacciSequence(n)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
def fibonacci( n ) | ||
def FibonacciSequence( n ) | ||
return n if ( 0..1 ).include? n | ||
( fibonacci( n - 1 ) + fibonacci( n - 2 ) ) | ||
( FibonacciSequence( n - 1 ) + FibonacciSequence( n - 2 ) ) | ||
end | ||
puts fibonacci( 5 ) | ||
|
||
DEFAULT = 10 | ||
|
||
n = DEFAULT | ||
|
||
if ARGV.length > 0 | ||
n = ARGV[0].to_i | ||
else | ||
puts "Which Fibonacci index to find? " | ||
n = ARGF.gets.to_i | ||
end | ||
|
||
if n < -1 | ||
n = DEFAULT | ||
end | ||
|
||
puts "Fibonacci sequence number at index #{n} is #{FibonacciSequence(n)}" |