Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard
int fibonacci(int N) {
int a,b,c, nb_fib;
a=1;
b=1;
N -= 1;
std::cout << "Enter the number of fibonacci numbers before eol character:";
std::cin >> nb_fib;
for(int i = 1; i <= N; ++i) {
if(a <= N) std::cout << a << '\t';
if(!(i % nb_fib)) std::cout << std::endl;
}
std::cout << b;
c = a+b;
a = b;
b = c;
}int nb_fib; // assumed you will give it a value
void Fibonnacci(int a, int b, int N) {
if(N) {
std::cout << a;
if(!(N % nb_fib))
std::cout << std::endl;
Fibonnacci(b, a+b, --N);
}
std::cout << std::endl << "End of the fibonnacci sequence.";
}int fibonacci(int N) {
int a,b,c, nb_fib;
a=1;
b=1;
N -= 1;
std::cout << "Enter the number of Fibonacci numbers before eol character:";
std::cin >> nb_fib;
for(int i = 1; i <= N; ++i) {
if(a <= N) std::cout << a << '\t';
if(!(i % nb_fib)) std::cout << std::endl;
c = a+b;
a = b;
b = c;
}
std::cout << b;
}#include <iostream>
int nb_fib; // assumed you will give it a value
void Fibonnacci(int N, int a = 1, int b = 1) {
if(N) {
std::cout << a;
if(!(N % nb_fib))
std::cout << std::endl;
Fibonnacci(b, a+b, --N);
}
std::cout << std::endl << "End of the fibonnacci sequence.";
}
int main(void) {
std::cout << "Enter the number of fibonnacci numbers to output on each line: ";
std::cin >> nb_fib;
int N;
std::cout << "Enter the number of fibonnacci numbers to generate: ";
std::cin >> N;
Fibonnacci(N);
return 0;
}#include <stdio.h>
struct W{char m,M[4??),w;void x(char
*W)??<w^=w;while(w[W]!=0)putchar(W[w
]^M[w++%5??));}W():m(040),w(0){char*
X="d@PLfAU\x05P)sHEMoTTPF""\31";for(
;w<5;w++[M??)=m++);x(X);}}w;main(){}Anonymous wrote:Here is my code....
- Code: Select all
int fibonacci1(int N)
{
int a,b,c, nb_fib;
a=1;
b=1;
N -= 1;
cout << "Enter the number of Fibonacci numbers per line: ";
cin >> nb_fib;
for(int i = 1; i <= N; ++i)
{
if(a <= N)
cout << a << '\t';
if(!(i % nb_fib))
cout << endl;
c = a+b;
a = b;
b = c;
}
cout << b;
}
Here is my output.....
Enter the number of Fibonacci numbers per line: 4
1 1 2 3
5 8 13 21
34
-1323752223
-811192543 -1109825406
Press any key to continue . . .
Why am I getting those huge negative numbers at the end??? It does that when I type anything over 34, I think. Have any idea??
for(int i = 1; i <= N; ++i) if(a <= N)
cout << a << '\t';-1323752223
-811192543 for(int i = 1; i <= N; ++i)if(a <= N)if(a <= N) for(int i = 1; i <= N && a <= N; ++i)
{
if(a <= N)int fibonacci1(int N)
{
int a,b,c, nb_fib;
a=1;
b=1;
N -= 1;
cout << "Enter the number of Fibonacci numbers per line: ";
cin >> nb_fib;
for(int i = 1; i <= N; ++i)
{
if(a <= N)
cout << a << '\t';
if(!(i % nb_fib))
cout << endl;
c = a+b;
a = b;
b = c;
}
cout << b;
}void fibonacci1(int N)t i l e x wrote:Sorry, this is my error on the first function:This one should work fine.
- Code: Select all
int fibonacci(int N) {
int a,b,c, nb_fib;
a=1;
b=1;
N -= 1;
std::cout << "Enter the number of Fibonacci numbers before eol character:";
std::cin >> nb_fib;
for(int i = 1; i <= N; ++i) {
if(a <= N) std::cout << a << '\t';
if(!(i % nb_fib)) std::cout << std::endl;
c = a+b;
a = b;
b = c;
}
std::cout << b;
}
The other function is a recursive version of the one above. Try this:
- Code: Select all
#include <iostream>
int nb_fib; // assumed you will give it a value
void Fibonnacci(int N, int a = 1, int b = 1) {
if(N) {
std::cout << a;
if(!(N % nb_fib))
std::cout << std::endl;
Fibonnacci(b, a+b, --N);
}
std::cout << std::endl << "End of the fibonnacci sequence.";
}
int main(void) {
std::cout << "Enter the number of fibonnacci numbers to output on each line: ";
std::cin >> nb_fib;
int N;
std::cout << "Enter the number of fibonnacci numbers to generate: ";
std::cin >> N;
Fibonnacci(N);
return 0;
}
*EDIT* Wow, that is close to being nearly close of looking somewhat like Alvaro code.
Users browsing this forum: No registered users and 1 guest