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 sort two array of characters and make a new array of characters.

1 Answers   Accenture,


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

2 Answers   Cap Gemini, HCL,


How to use c/c++ code in JAVA

10 Answers   CDAC, IBM, Satyam, Scope International,


How do you determine the length of a string value that was stored in a variable?

0 Answers  


Where is volatile variable stored?

0 Answers  


How can you increase the allowable number of simultaneously open files?

0 Answers  


How is a macro different from a function?

0 Answers   Tech Mahindra,


How can type-insensitive macros be created?

0 Answers  


How to swap 3 numbers without using 4th variable?

5 Answers  


What is the use of getchar() function?

0 Answers  


What is the difference between void main and main in c?

0 Answers  


What is the difference between malloc() and realloc()?

2 Answers  


Categories