473,408 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

C fibonacci sequence

I wanna wright C programe to find value F(n)value with in(0=<n<=20),programme must be we input n valu then we get out put F(n) value.
fibonacci sequence
F(n)=F(n-1)+F(n-2)
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int n,ans=0,n1=0,n2=0,i,p;
  5. printf("enter n:");
  6. scanf("%d",&n);
  7. p=n;
  8. if(n==0)
  9. printf("%d",n1);
  10. if(i==1)
  11. printf("%d",n2);
  12. else
  13. for(i=0;i<p-2;p++)
  14. {
  15. ans=n1+n2;
  16. n1=n2;
  17. ans=n2;
  18. }
  19. printf("%d",ans);
  20. return 0;
  21. }
but i got this error
Building fib.exe.
POLINK: fatal error: Access is denied.
*** Error code: 1 ***
Done.


plz find the error in this progm..
Sep 3 '10 #1
2 2105
haicp
4
This program compiles perfectly. But goes into an infinite loop.

The problem is,
a) the value of i is not initialised to execute if(i==1) condition
b) the for(i=0;i<p-2;p++) loop never breaks for any value > 2
c) if the for loop is changed to for(i=0;i<p-2;i++) then this will not be an infinite loop
d) even then the value of ans will be zero because the values of n1 & n2 are never changed (updated)
Sep 3 '10 #2
Banfa
9,065 Expert Mod 8TB
Following haicps observation that the program enters an infinite loop the reason for the "Access is Denied" is most likely that the program is still running from when you previously tested it. On windows while running programs executable file is locked so the linker can not open it to write the new output.

This error is not caused by an error in the code (which does not equate to the code being error free see haicps post).
Sep 3 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: misho | last post by:
Write a C program using the fork() system call that that generates the Fibonacci sequence in the child process. The number of the sequence will be provided in the command line. For example, if 5 is...
6
by: Andrew Tatum | last post by:
I'm having some problems with the below equation. I have no problems when it comes to positives. Negatives create the problem.. C 2 1 4 However, this doesn't work:
5
by: coleslaw01 | last post by:
Hello, I am trying to teach myself C++ while babysitting a stable network in Iraq and have put together a program to display the fibonacci sequence. It works with long and long double(output in...
28
by: DaemonCoder | last post by:
The challenge is to create the shortest algorithim, In any programming language. RULES: 1. All code must be on one line. 2. Languages that prevent this are disallowed. I.E Assembly, and of...
16
by: showellshowell | last post by:
I would like to present an unusual take on computing the Fibonacci sequence using Javascript. Please try out the following link in Firefox (sorry, having problems with other browsers): ...
1
by: tlalzo | last post by:
how can I write a fibonnaci sequence up n iteratively where n is given by the user and the program must display all the numbers of the sequence up to n.
8
by: sedaw | last post by:
need to print the n fibonacci number . this is my work dont know why it isnt workin . #include <stdio.h> void main() { int n, F0=0, F1=1, F, i=0; printf("N=?/n"); scanf("%d", &n);
1
by: altaey | last post by:
Question Details: Write a program to find and print a Fibonacci sequence of numbers. The Fibonacci sequence is defined as follow: Fn = Fn-2 + Fn-1, n >= 0 F0 = 0, F1 = 1, F2 = 1 Your...
3
by: nikid72 | last post by:
I am having a problem with a program I have written, the requirements were to "Write a function that computes and returns the n-th Fibonacci number. The main should invoke that function and print...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.