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

add Fibonacci #2015

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions 6thJune_Dyang.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// PROGRAM TO: Print Fibonacci numbers up to 'n' numbers and replacing multiples of 5 and prime numbers with 0
//test


import java.util.*;

public class fibonacci
{
public static void main(String args[])
{
Scanner inp = new Scanner(System.in);

int n, sum, n1 = 1, n2 = 1, marker;
System.out.println("Enter the limit:");
n = inp.nextInt();
System.out.print(n1);
System.out.print(" ");
System.out.print(n2);
System.out.print(" ");
for (int i = 2; i < n; i++) {
marker = 0;
sum = n1+n2;
if (sum %5 ==0)
System.out.print("0 ");
else {
for (int j = 2; j < sum /2; j++)
{
if (sum % j == 0)
{
System.out.print(sum+" ");
marker = 1;
break;
}
}
if (marker == 0)
System.out.print("0 ");
}

n1 = n2;
n2 = sum;
}
}
}
//test
52 changes: 52 additions & 0 deletions fibonacci-6thJune.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//Fibonacci Series with a Twist

#include<bits/stdc++.h>
using namespace std;

bool prime(int n)
{
if (n <= 1)
return false;


for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;

return true;
}

int fibonacci(int n)
{
int a = 1, b = 1, c, i;
//Corner case
if( n == 0)
return 0;
else if ( n == 1 )
{
cout << "1 ";
return 0;
}
cout << "1 1 ";
for(i = 3; i <= n; i++)
{
c = a + b;
//Condition check
if ( c % 5 != 0 && !prime( c ))
cout << c << " ";
else
cout << "0 ";
a = b;
b = c;
}
return b;
}

int main()
{
int n = 0;
cout << " Please enter the value of n : ";
cin >> n;
fibonacci(n);
return 0;
}