answersLogoWhite

0


Best Answer

#include<iostream>

using namespace std;

#define MIN 1

#define MAX 1000000

int main()

{

int num;

char c;

do

{

cout << "Enter a number from " << MIN << "-" << MAX << " (0 to quit): ";

cin >> num;

while(cin.fail() num < 0 num > MAX)

{

if( cin.fail() )

{

cin.clear();

cin >> c;

}

cout << "Invalid number, try again: ";

cin >> num;

}

if(num)

{

cout << "\nFibbonacci series for n, where 1 <= n <= " << num << ":\n\n";

int n = 1, x = 0, y = 0;

do

{

cout << n;

x = y;

y = n;

n = x + y;

if( n < num )

cout << ", ";

}while( n < num );

cout << endl << endl;

}

}while( num );

return( 0 );

}

User Avatar

Wiki User

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

Wiki User

12y ago

Before jumping to program we will look how Fibonacci series are generated.

Fibonacci series is linear sequence of integers, there first one is 0 and second one is 1. Now all other elements are generated using this rule: Fn+1 = Fn + Fn-1.

0 1 1 2 3 5 8 13 21 34 55 89 ...

...

34 = 21 + 13

55 = 34 + 21

89 = 55 + 34

...

Here is small program that does the same and it uses do-while loop:

#include

int main() {

int num = 0;

int a = 0, b = 1;

int count = 0;

printf("How many numbers you want? (3 mininmum) ");

scanf("%d", &num);

printf("0 1 ");

do {

b = a + b;

a = b - a;

b = a + b - a;

printf("%d ", b);

count++;

} while (count <= num - 3);

printf("\n");

return 0;

}

Testing:

How many numbers you want? (3 mininmum) 20

0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Yes....Here is the code....

#include <stdio.h>

public int main() {

int num1 = 0;

int num2 = 0;

int num3;

int maxlimit;

printf("Enter the maximum limit of Fibonacci series : ");

scanf(%d",&maxlimit);

printf("%d\t", num1,num2);

num3 = num1 + num2;

if (maxlimit > 0) {

while ( num3 < maxlimit) {

printf("%d",num3);

num3 = num1 + num2;

num1 = num2;

num2 = num3;

}

}

else

printf("Invalid limit !");

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

public class fib{

public static void main(String[] args){

int count=0;

int i=0;

int j=1;

do{

System.out.println(j+" ");

int k= i+j;

i=j;

j=k;

}

while (++count<15);

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program to print fibonacci series using do while loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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).

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