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 does c mean in basketball?

0 Answers  


Is double link list a linear data structure? If Yes, Why?If No, Why?

4 Answers  


What is the difference between printf and scanf in c?

0 Answers  


main() { int i = 10; printf(" %d %d %d \n", ++i, i++, ++i); }

10 Answers   TCS, Vector,


How to removing white spces in c programming only bu using loops

2 Answers  






How do you generate random numbers in C?

0 Answers  


Write a simple code fragment that will check if a number is positive or negative.

0 Answers  


which one is highest Priority in c? a)=,b)+,c)++,d)==

4 Answers  


Determine the code below, tell me exactly how many times is the operation sum++ performed ? for ( i = 0; i < 100; i++ ) for ( j = 100; j > 100 - i; j--) sum++;

5 Answers   ITCO, Wipro,


Given an array of numbers, except for one number all the others occur twice. Give an algorithm to find that number which occurs only once in the array.

6 Answers  


int main() { int *p=new int; *p=10; del p; cout<<*p; *p= 60; cout<<*p; } what will be the output & why?

4 Answers   TCS,


What is the use of structure padding in c?

0 Answers  


Categories