Question about Operating Systems

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

Add Your Answer

Uploading: 0%

my-video-file.mp4

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

×

Loading...
Loading...

Related Questions:

1 Answer

Debug error


An "assertion" is a booby-trap inside a computer program.

Under normal conditions, the programmer has determined that his/her program will always find that the \'ASSERT\' statement is "true", e.g., \'ASSERT X > 0\'. However, in your case, somehow the value of \'X\' makes the statement to be "false". Then, the program "stops", due to something seriously being "wrong".

It\'s either some incorrect input data being fed to the program, or a "software-bug" inside the program.

Check your input.

Contact the author of the program.

Mar 13, 2014 | Microsoft XP Operating Systems

1 Answer

Write a programme that takes three numbers as input from the user and find out wheather one of the three numbers is the airthmetic mean of the other two. for example : input: 7, 11, 15 output: 11 is...



Since you are taking a class in binary programming; I would recommend you figure this out yourself. The major point in logic class is to determine ways to solve this on your own. If you are unable to do this; I would suggest a change of major.

Jan 29, 2011 | Operating Systems

1 Answer

I have installed adobe acrobat8 how can i find the serial number for adobe8


If you go to GOOGLE on your Internet browser and type in there ' Adobe acrobat 8 Keygen'
This should bring up lists of site that can provide you with a serial number so you can input this into adobe program.

Hope this helps you out. Please leave a thumbs up if this sorts you out

Thanks Little Dish Fitter

Sep 28, 2009 | Microsoft Windows? Vista Home Premium...

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 | Operating Systems

1 Answer

A c prog to convert decimal to hexadecimal number.


Sure, here you go:

int main(void) {
int input;
printf("Enter a decimal number: ");
scanf("%d", &input);
printf ("In hexadecimal, that is: %X\n\n", input);
return 0;
}

Oct 05, 2008 | Operating Systems

2 Answers

Pattern matching


Nice try!

It's been almost 15 months since you asked your question.

If nobody has helped you with your "homework" assignment,
you probably scored a "zero" on your computer-programming course,
and probably no longer need an answer to your problem.

Sep 12, 2008 | Operating Systems

1 Answer

How to create program in delphi


i wants to create form for data input
with the condition

Mar 13, 2008 | Operating Systems

1 Answer

Plz give me C code for the given program


I have the code in java. can you convert.
if need
mail to p.stivel@gmail.com

Feb 23, 2008 | Operating Systems

1 Answer

VIsta Ultimate, Tablet PC input panel (TIP)


You should be able to do that..if not try going to device manager and update the driver there. Possible put Vista CD in and reinstall the program.

Nov 10, 2007 | Microsoft Windows Vista Ultimate Edition

Not finding what you are looking for?
Operating Systems Logo

Related Topics:

139 people viewed this question

Ask a Question

Usually answered in minutes!

Top Operating Systems Experts

Les Dickinson
Les Dickinson

Level 3 Expert

18298 Answers

Brian Sullivan
Brian Sullivan

Level 3 Expert

27725 Answers

Prashant  Sharma
Prashant Sharma

Level 3 Expert

1127 Answers

Are you an Operating System Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...