answersLogoWhite

0


Best Answer

fibbonacci starts out as 1,1,2,3,5,8,13,21,34....meaning 1 + 1 = 2, 2 +1 = 3, 3+2 = 5 and so on the solution in C++.

#include <iostream>

using namespace std;

int main()

{

short a = 1;

short b = 1;

short c = 2;

do

{

a = c + b;

cout << a << "\n";

b = a + c;

cout << b << "\n";

c = b + a;

cout << c << "\n";

}while (a && b && c != 34);

return 0;

}

in this i used short int because, i was only going to go up to 34 to keep things short an simple.

I then figured out in what order i would have to figure out my variables on paper. I assigned values to my variables to have a starting point then used a do-while to loop the program. I made sure that my varibles were all checked against 34 so it would have a break point and not run on forever.

User Avatar

Wiki User

16y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

Every computer language has different syntax, so writing a set program without knowing the language is infeasible. However, the general algorithm for generating a Fibonacci sequence is as follows. Input -> n; temp1 = 0; temp2 = 1; temp3 = 0; if (n = 0), output: temp1; else if (n = 1), output: temp2; else output: temp1; output: temp2; for loop (base: 0, check: n-1, base++) {temp3 = temp2 + temp1; output: temp3; temp2 = temp1; temp1 = temp3;}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

// recursive method - very slow for larger numbers

unsigned long fib (unsigned long n) {

if (n 2) return 1;

return fib (n-1) + fib (n-2);

}

int main (int argc, char* argv[]) {

unsigned long n, f;

for (n = 1; n < 50; ++n) {

f = fib(n);

if (f > 100) break;

printf ("%lu %lu\n", n, f);

}

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

#include<stdio.h>

void main()

{

int arr[12],n;

int a=0,b=1,c,i,j,flag=0;

arr[0]=a;arr[1]=b,i=2;

clrscr();

printf("\nEnter the values:");

scanf("%d",&n);

do

{

c=a+b;

arr[i++]=c;

a=b;

b=c;

} while(c<n);

printf("\nNon Fibnoacci series is:");

for(i=0;i<n;i++)

{

flag=0;

for(j=0;j<10;j++)

{

if(i==arr[j])

{

flag=0;

break;

}

else

flag=1;

}

if(flag==1)

{

printf("%d ",i);

}

}

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

function fib() { local x y z n; x=1; for n in `seq 1 $1` ; do z=$((x+y)); echo -e "$n\t:\t$z"; x=$y; y=$z; done; }

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

a=0

b=1

c=0

For i=0 to whaterveryouwant

print c

c=a+b

a=b

b=c

next i

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to print the Fibonacci series 0 1 1 2 3 5 8-------20?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a java program to print the last digit in Fibonacci series?

Just generate the Fibonacci numbers one by one, and print each number's last digit ie number%10.


Write a C program to print the following series 112 122 . 1n2?

write a program to print the series 1/12+1/22+.........+1/n2 ?


Write a program to print the Fibonacci series in php upto input value using recursive function?

The Fibonacci sequence uses recursion to derive answers. It is defined as: F0 = 0 F1 = 1 Fn = F(n - 1) + F(n -2) To have this sequence printed by a php script use the following: function fibonacci($n) { if($n 1) return 1; //F1 else return fibonacci($n - 1) + fibonacci($n - 2); //Fn } This recursive function will print out the Fibonacci number for the integer n. To make it print out all the numbers in a particular set add this to your script. for($i = 0; $i &lt; 15; $i++) { echo fibonacci($i) . "&lt;br /&gt;"; } So your final result would look like. &lt;?php function fibonacci($n) { if($n 1) return 1; else return fibonacci($n - 1) + fibonacci($n - 2); } for($i = 0; $i &lt; 15; $i++) { echo fibonacci($i) . "&lt;br /&gt;"; } ?&gt;


How do you write a program to print Fibonacci series of n numbers using recursion in cpp?

#include&lt;iostream&gt; unsigned fib (unsigned term, unsigned a=0, unsigned b=1) { if (term&lt;1) return a; return fib (--term, a+b, a); } int main() { std::cout &lt;&lt; "Fibonacci (1000th term): " &lt;&lt; fib (1000) &lt;&lt; std::endl; }


Write a java program to print the result in the series?

If you have the series stored in an array, you loop through the array and print each array element in turn. Another possibility is to print out the numbers in the series as you generate them. In that case, you may not need to store anything (depending on the series, of course).

Related questions

Write a C program to print the following series 112 122 . 1n2?

write a program to print the series 1/12+1/22+.........+1/n2 ?


Write a java program to print the last digit in Fibonacci series?

Just generate the Fibonacci numbers one by one, and print each number's last digit ie number%10.


Write a program to print the Fibonacci series in php upto input value using recursive function?

The Fibonacci sequence uses recursion to derive answers. It is defined as: F0 = 0 F1 = 1 Fn = F(n - 1) + F(n -2) To have this sequence printed by a php script use the following: function fibonacci($n) { if($n 1) return 1; //F1 else return fibonacci($n - 1) + fibonacci($n - 2); //Fn } This recursive function will print out the Fibonacci number for the integer n. To make it print out all the numbers in a particular set add this to your script. for($i = 0; $i &lt; 15; $i++) { echo fibonacci($i) . "&lt;br /&gt;"; } So your final result would look like. &lt;?php function fibonacci($n) { if($n 1) return 1; else return fibonacci($n - 1) + fibonacci($n - 2); } for($i = 0; $i &lt; 15; $i++) { echo fibonacci($i) . "&lt;br /&gt;"; } ?&gt;


How do you write a program to print Fibonacci series of n numbers using recursion in cpp?

#include&lt;iostream&gt; unsigned fib (unsigned term, unsigned a=0, unsigned b=1) { if (term&lt;1) return a; return fib (--term, a+b, a); } int main() { std::cout &lt;&lt; "Fibonacci (1000th term): " &lt;&lt; fib (1000) &lt;&lt; std::endl; }


Write a java program to print the result in the series?

If you have the series stored in an array, you loop through the array and print each array element in turn. Another possibility is to print out the numbers in the series as you generate them. In that case, you may not need to store anything (depending on the series, of course).


Write an assembly language program to print a to z on screen?

write a program to print A to Z on screen in c?


What is the program to print Fibonacci series in qbasic?

CLS a = 0 b = 0 FOR i = 1 TO 10 IF a = 0 THEN f = 1 END IF PRINT f b = a a = f f = a + b NEXT i END from : Parth jani parthjani7@yahoo.com


Write a unix program to print print a pattern?

echo 'print a pattern'


Write a java script program to print first ten odd natural numbers in C?

Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.


Write a C program Fibonacci using normal loops and conditional statements?

to print the Fibonacci series until 100 you can take the input in d to make it run for whatever value you want void main(){ int a,b,c,d; a=0; b=1; c=1; d=100; while(c&lt;d) { printf("%d\n",c); c=a+b; a=b; b=c; } }


Write a program in BASIC to find the sum of the series s equals 2 plus 4 plus . plus 100?

10 print "That is not a question." 20 print "That is a command." 30 end


Write a shell program to generate fibnacci series using while loop?

//WAP to print fibonacci series using do-while loop.? using System; class Fibonacci { public static void Main() { int a=1,b=1; int sum=0; Console.Write("Enter Limit:"); int n=Int32.Parse(Console.ReadLine()); Console.Write(a); Console.Write(b); do { sum=a+b; a=b; b=sum; Console.Write(sum); } while(sum&lt;n); } } By-Vivek Kumar Keshari