write a program for fibonaci series by using while loop in c?

Answers were Sorted based on User's Feedback



write a program for fibonaci series by using while loop in c?..

Answer / rajendra raji

main()
{
int a=0,b=1,c,n;
printf("enter n value");
scanf("%d",&n);
Printf("%d%d",a,b);
n=n-2;
while(n>0)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
n--;
}
}

Explanation:
Hi....
if you give n value as 5, then it will print 5 values including the first printed a and b values..!!
try it once.. it will definitely work..

Is This Answer Correct ?    2 Yes 0 No

write a program for fibonaci series by using while loop in c?..

Answer / shamantha

main()
{
int a=0,b=1,c,n;
printf("enter n value");
scanf("%d",&n);
Printf("%d%d",a,b);
while(n-2>0)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
n=n+1;
}
}

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More C Interview Questions

What are the phases in s/w developed life cycle? wat is the diff b/w stack & queue...where do we use stack

6 Answers  


How can you invoke another program from within a C program?

0 Answers  


What are local static variables?

0 Answers  


What is the advantage of a random access file?

0 Answers  


explain how do you use macro?

0 Answers  






Go through the following code sinippet char a[20]; a="Hello Orcale Test"; will this compile?

4 Answers   Oracle,


How is = symbol different from == symbol in c programming?

0 Answers  


Why c language?

0 Answers  


Input any no. and print all the the numbers that comes before it like this for e.g input = 4 0 01 012 0123 01234 plz answer it 2day

3 Answers  


What are pointers? Why are they used?

0 Answers  


What is scope and lifetime of a variable in c?

0 Answers  


How does free() know how many bytes to free?

8 Answers  


Categories