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

implement NAND gate logic in C code without using any bitwise operatior.

4 Answers   Alcatel,


Do you know what is a programing language ?

0 Answers  


What is the use of c language in real life?

0 Answers  


int i=0,j; j=++i + ++i ++i; printf(" %d",j);

2 Answers   ME,


find second largest element in array w/o using sorting techniques? use onle one for loop.

15 Answers   BitWise, Zycus Infotech,






how write a addtion of two single dimensional array using of pointer in c language?

3 Answers   DRDO,


Explain the Difference between the New and Malloc keyword.

0 Answers   InterGraph,


Is c dynamically typed?

0 Answers  


Explain the bubble sort algorithm.

0 Answers  


write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.

0 Answers   Subex,


When should you use a type cast?

0 Answers  


What are the general description for loop statement and available loop types in c?

0 Answers  


Categories