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

how to set Nth bit of a variable?

1 Answers  


hat is a pointer?

4 Answers   Assurgent,


how to determine the complexity of an algorithm as log(n)

1 Answers   Google,


Three major criteria of scheduling.

1 Answers  


what is meant by the "equivalence of pointers and arrays" in C?

3 Answers   Satyam,






Explain what is wrong with this program statement?

0 Answers  


what is an array

5 Answers  


Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

0 Answers  


What are the Advantages of using macro

0 Answers  


c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above

0 Answers  


what is c

1 Answers  


What is hashing in c?

0 Answers  


Categories