Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C version with comment #50

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
29 changes: 29 additions & 0 deletions Fibonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<stdio.h>

int main(void){

unsigned long fib1= 0, fib2= 1, fib3;
int start;

printf("input the index value: ");
scanf("%d",&start); // enter the index value from console by user
// input value more than 100, OK

switch(start){
case 0: // if index value is 0
printf("F0 = %lu\n", fib1); // print the fibonacci(0)
break;
case 1: // if index value is 1
printf("F1 = %lu\n", fib2); // print the fibonacci(1)
break;
default: // if index value more than 1
for(int i=0; i<=(start-2); i++){ // calculate the result and print process and result
fib3= fib1 + fib2;
printf("F%d = %lu, F%d = %lu, F%d = %lu\n", i, fib1, i+1, fib2, i+2, fib3);
fib1= fib2;
fib2= fib3;
}
}

return 0;
}
16 changes: 12 additions & 4 deletions Fibonacci.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import java.util.Scanner;



public class Fibonacci{
public static void main(String []args){

long start;
if (args.length == 0){
System.out.println("please enter the argument. Input number must be under 93");
return;

Scanner input= new Scanner(System.in);
System.out.print("Enter the value: ");
start= input.nextLong();
}
long start = Integer.parseInt(args[0]);
else
start = Integer.parseInt(args[0]);
long fib1 = 0;
long fib2 = 1;
if (start < 2){
Expand All @@ -23,4 +31,4 @@ public static void main(String []args){
fib2 = fib3;
}
}
}
}
15 changes: 15 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,18 @@ F6 = 8, F7 = 13, F8 = 21
F7 = 13, F8 = 21, F9 = 34
F8 = 21, F9 = 34, F10 = 55
{code}

* c version compile
**noirCynical-ui-MacBook-Air:gdg_codelab_1404 noirCynical$ gcc Fibonacci.c
**noirCynical-ui-MacBook-Air:gdg_codelab_1404 noirCynical$ ./a.out
input the index value: 10
F0 = 0, F1 = 1, F2 = 1
F1 = 1, F2 = 1, F3 = 2
F2 = 1, F3 = 2, F4 = 3
F3 = 2, F4 = 3, F5 = 5
F4 = 3, F5 = 5, F6 = 8
F5 = 5, F6 = 8, F7 = 13
F6 = 8, F7 = 13, F8 = 21
F7 = 13, F8 = 21, F9 = 34
F8 = 21, F9 = 34, F10 = 55