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
73 additions
and
24 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,25 @@ | ||
// Simple Program to calculate Fibonacci Sequence of an integer input | ||
#include <iostream> | ||
#include <cstdlib> | ||
using namespace std; | ||
|
||
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; | ||
if (argc > 1) { | ||
for(int i = 1; i < argc; i++) { | ||
n = atoi(argv[i]); | ||
cout << "Fibonacci sequence number at index " << n << " is " << FibonacciSequence(n) << endl; | ||
} | ||
} else { | ||
cout << "Which Fibonacci index to find? "; | ||
cout.flush(); | ||
cin >> 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,27 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
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; | ||
if (argc > 1) { | ||
int i; | ||
for(i = 1; i < argc; i++) { | ||
n = atoi(argv[i]); | ||
printf("Fibonacci sequence number at index %d is %d\n" , n , FibonacciSequence(n)); | ||
} | ||
} else { | ||
printf("Which Fibonacci index to find? "); | ||
int matched = scanf("%d", &n); | ||
if (matched < 1) { | ||
n = 10; | ||
} | ||
printf("Fibonacci sequence number at index %d is %d\n" , 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,32 @@ | ||
// Simple Program to calculate fibonacci of input | ||
|
||
package main | ||
|
||
import "fmt" | ||
func FibonacciRecursion(n int) int { | ||
import ( | ||
"fmt" | ||
"strconv" | ||
"os" | ||
) | ||
|
||
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) | ||
|
||
fmt.Println("Fibonacci of", n , "is", FibonacciRecursion(n)); | ||
if len(os.Args) > 1 { | ||
for _, arg := range os.Args[1:] { | ||
n, _ := strconv.Atoi(arg) | ||
fmt.Printf("Fibonacci sequence number at index %d is %d\n" , n , FibonacciSequence(n)); | ||
} | ||
} else { | ||
var input string | ||
fmt.Print("Which Fibonacci index to find? ") | ||
fmt.Scanln(&input) | ||
n, err := strconv.Atoi(input) | ||
if err != nil { | ||
n = 10 | ||
} | ||
fmt.Printf("Fibonacci sequence number at index %d is %d\n" , 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,15 @@ | ||
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 | ||
|
||
if ARGV.length > 0 | ||
ARGV.each { |arg| | ||
n = arg.to_i | ||
puts "Fibonacci sequence number at index #{n} is #{FibonacciSequence(n)}" | ||
} | ||
else | ||
puts "Which Fibonacci index to find? " | ||
n = ARGF.gets.to_i | ||
puts "Fibonacci sequence number at index #{n} is #{FibonacciSequence(n)}" | ||
end | ||
puts fibonacci( 5 ) |