Question about Computers & Internet

1 Answer

Input a number and then show the fibonacci sequence of the input number in a C++ program.

Posted by on

1 Answer

  • Level 1:

    An expert who has achieved level 1.

  • Contributor
  • 4 Answers

I'm assuming one of two things, either

A) You need help for a programming class?

or

B) You're just curious?

Either way

#include <iostream>
#include <algorithm>
using std::swap;
using std::cout;
using std::endl;
// Function f returns n'th Fibonacci number
// It uses Algorithm 2C: non-recursive loop
unsigned int f(unsigned int x) {
unsigned int x1=1;
for(unsigned int i=1,x2=1;i<=x;i++) {
x1+=x2;
swap(x1,x2);
}
return x1;
}
// Function f_print prints out n'th Fibonacci number
void f_print(int n) {
cout << n << "th Fibonacci number is " << f(n) << endl;
}
// main is the entry point in C++
int main() {
f_print(46);
}

Posted on Feb 18, 2009

1 Suggested Answer

6ya6ya
  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

Hi,
a 6ya expert can help you resolve that issue over the phone in a minute or two.
best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).
click here to download the app (for users in the US for now) and get all the help you need.
goodluck!

Posted on Jan 02, 2017

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

2 Answers

I need three numbers for lunchtime today please help me please


not a technical problem for fixya site

Nov 22, 2016 | Optics

1 Answer

Sample of how to create a python program that will input two numbers and will ask the user of operation to perform as to addition,subtraction,multiplication or division the program should perform the...


Assuming that the input numbers are given by the user:print "Menu"print "1. Addition"print "2. Subtraction"print "3. Multiplication"print "4. Division"print "0. Quit"
a = input("Please make a selection:")if a == 1: x = input("Please enter a number:") y = input("Please enter another number:") answer = x + yprint "%r plus %r = %r" % (x,y,answer)elif a == 2: x = input("Please enter a number:") y = input("Please enter another number:") answer = x - yprint "%r minus %r = %r" % (x,y,answer)
The same goes for everything else just with different signs. Don't forget that "*" is multiplication and "/" is division. Also, for 0. Just use:
elif a == 0: quit

Sep 28, 2011 | Computers & Internet

1 Answer

Wirte a pogram in java using for loop,that will print out the first 1 numbers of a fibonacii series that is:1 1 2 3 5 13 21 34 55


package com.gpt;

import javax.swing.JOptionPane;

/*
This program computes Fibonacci numbers using a recursive
method.
*/
public class Fibonacci
{
public static void main(String[] args)
{
String input = JOptionPane.showInputDialog("Enter n: ");
int n = Integer.parseInt(input);

for (int i = 1; i {
int f = fib(i);
System.out.println("fib(" + i + ") = " + f);
}
System.exit(0);

}

/**
Computes a Fibonacci number.
@param n an integer
@return the nth Fibonacci number
*/
public static int fib(int n)
{
if (n return 1;
else
return fib(n - 1) + fib(n - 2);
}
}

Feb 24, 2011 | Sun Java Programming Language (cdj-275)

3 Answers

Fibonacci formula won't graph, but will show table


Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
At first type Fibonacci equation in Y editor with condition x>=0 and then graphing it. See captured images with enlarged form of graph

7_31_2012_12_55_37_pm.jpg


7_31_2012_12_57_51_pm.jpg


7_31_2012_12_58_57_pm.jpg

Apr 11, 2010 | Texas Instruments TI-84 Plus Silver...

3 Answers

Write algorithm that displays the first N numbers in Fibonacci


Try this site, I think it gives you the best answer:

http://www.scribd.com/doc/10396888/Flowchart-of-Fibonacci-Number-Display-and-Summation

Feb 14, 2010 | Global Marketing Partners FLOWCHARTS AND...

1 Answer

Please Solve this C++ Program


Write a program to prompt the user to input several lines of input. A line of inputs is terminated by '*'. For each readline of input the program should output:(use pointer notation for the array) . The total # of words . The lenght of the longest word in the line At the end the program should output: . The total number of words read in all lines of input . The lenght of the longest word read in all lines of input

Jan 19, 2009 | Computers & Internet

1 Answer

Memory program ch no# on icom u or h16


I had the same problem. I solved it by going into program mode, then while holding down the function key, input one of the missing channel numbers. The channel should appear but is flashing. Now input a frequency for the channel and exit program mode. Repeat the sequence for the other missing channels. This procedure worked for me. Good luck.

Nov 19, 2008 | ICOM Informatique Icom Radio U16, IC2GAT,...

3 Answers

I need solve this type calulation is 0,1,1,2,3,5,8,13,21,34 etc. u send me the code of this type of calculation in c++ language


Ok! Here's a snippit from some code I wrote in beginning c++ classes. However, don't just cut and paste it. Know how it works since it's important in algorithm examination!

Just tested it, compiles and runs perfectly on GCC 4.0.1 on my mac, as well as my linux boxen. Windows may take some changes to output data.

/***********************************************
* Steven Parker
* Calculating Fib Sequence
* after two starting values, each number is the
* sum of the two preceding numbers
***********************************************/
#include <iostream>
using namespace std;

int main() {
int whentostop = 20; //How many values of sequence to calculate
int fib[whentostop]; //Hold fib numbers

for (int i=0; i < whentostop; i++) {
if (i == 0)
fib[0] = 0;
else if (i == 1)
fib[1] = 1;
else
fib[i] = fib[i-1] + fib[i-2];

cout << "Fibonacci[" << i << "]: " << fib[i] << endl;
}
return 0;
}

Nov 12, 2008 | Computers & Internet

Not finding what you are looking for?
Computers & Internet Logo

Related Topics:

142 people viewed this question

Ask a Question

Usually answered in minutes!

Top Computers & Internet Experts

Brian Sullivan
Brian Sullivan

Level 3 Expert

27725 Answers

kakima

Level 3 Expert

101608 Answers

David Payne
David Payne

Level 3 Expert

14160 Answers

Are you a Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...