ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
compute the nth mumber in the fibonacci sequence?
 Question Submitted By :: Prabhakar Kansal
I also faced this Question!!     Rank Answer Posted By  
 
  Re: compute the nth mumber in the fibonacci sequence?
Answer
# 1
#include<stdio.h>
#include<conio.h>

void main()
{
 int n;
 void fib(int n);
 clrscr();

 printf("Enter any no.");
 scanf("%d",&n);
 clrscr();

 printf("Hit any key to continue");
 getch();
 clrscr();
 printf("Fibonacci of %d is \n");
 fib(n);

 getch();

}
 void fib(int n)
 {
  static int x,y;
  int temp;
  if(n<=1)
  {
   x=0;
   y=1;
  }
  else
  {
   fib(n-1);
   temp=y;
   y=x+y;
   x=temp;
  }
  printf(" %d\n",x);

  return;
}
 
Is This Answer Correct ?    3 Yes 1 No
Ravi Kumar Gupta
 
  Re: compute the nth mumber in the fibonacci sequence?
Answer
# 2
#include<stdio.h>
#include<conio.h>
void main()
{
 int a=0,b=1,c,n,i;
 clrscr();
 printf("Enter n:");
 scanf("%d",&n);
 printf("The fibonacci sequence is as follows : \n");
 for(i=1;i<=n;i++)
 {
   c=a+b;
   printf("%d ",c);
   a=b;
   b=c;
 } 
 printf("The nth number in the fibonacci sequence is : %d",c);
 getch();
}
 
Is This Answer Correct ?    10 Yes 1 No
Theredplanethavoc
 
 
 
  Re: compute the nth mumber in the fibonacci sequence?
Answer
# 3
// n th number of a fibonacci series


#include<stdio.h>
#include<conio.h>

void main ()
{
	int i,k = 0 , j = 1 ,n,res;
	printf ( " \n enter the number " );
	scanf ( "%d",&n ) ;

//	printf ( "\n the series is 0, 1" ) ;

	for ( i= 2 ; i<n;i++ )
	{
		res= k+j ;
		k=j;
		j=res;
  //		printf ( ", %d" ,res ) ;
	}
	printf ( " \n The n th term is %d " ,res ) ;

	getch() ;
}
 
Is This Answer Correct ?    7 Yes 0 No
Selloorhari
 
  Re: compute the nth mumber in the fibonacci sequence?
Answer
# 4
main()
{ int a=0,b=1,c,n,i;
printf("enter nth number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
c=a+b;
printf("fibonacci series is %d",&c);
a=b;
b=c;
}
getch();
}
 
Is This Answer Correct ?    2 Yes 2 No
Sweety
 
  Re: compute the nth mumber in the fibonacci sequence?
Answer
# 5
#include<stdio.h>
#include<conio.h>
void main()
{
int n,a=-1,b=1,c;
printf("Enter n:");
scanf("%d",&n);
for(int i=0;i<=n;i++)
{
c=a+b;
a=b;
b=c;
}
printf("Answer:%d",c);
}
 
Is This Answer Correct ?    2 Yes 3 No
Sree
 
  Re: compute the nth mumber in the fibonacci sequence?
Answer
# 6
#include<stdio.h>
#include<conio.h>
void main()
{
int f=0,s=1,t,n,i;
clrscr();
printf("\nENTER THE VALUE OF N\n");
scanf("%d",&n);
if(n==1)
  printf("FIBONACCI NUMBER IS 0");
else if(n==2)
  printf("FIBONACCI NUMBER IS 1");
else
  {
    for(i=3;i<=n;i++)
      {
        t=f+s;
        f=s;
        s=t;
      }
    printf("\nFIBONACCI NUMBER IS %d",t);
  } 
getch();
}
 
Is This Answer Correct ?    2 Yes 1 No
Akshara
 
  Re: compute the nth mumber in the fibonacci sequence?
Answer
# 7
#include<stdio.h>
#include<conio.h>
void main()
{
int a=-1,b=1,c,n,i;
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
}
getch();
}
 
Is This Answer Correct ?    2 Yes 0 No
Dinesh Kumar .n
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
How can I invoke another program from within a C program?  6
WRITE A PROGRAM TO PRINT THE FOLLOWING OUTPUTS USING FOR LOOPS. A) * B) ***** *** * * ***** * * *****  2
Predict the output or error(s) for the following: 25. main() { printf("%p",main); } ME3
Can we write a program without main() function?  9
What will be result of the following program? void myalloc(char *x, int n) { x= (char *)malloc(n*sizeof(char)); memset(x,\0,n*sizeof(char)); } main() { char *g="String"; myalloc(g,20); strcpy(g,"Oldstring"); printf("The string is %s",g); } a) The string is : String b) Run time error/Core dump c) The string is : Oldstring d) Syntax error during compilation e) None of these IBM3
what is difference between array and structure? TCS19
How can I read a directory in a C program? Wipro1
What are bit fields? What is their use? Adobe1
WAP TO ACCEPT STRING AND COUNT A COMES N TIMES B COMES N TIMES C COMES N TIMES D COMES N TIMES AND SO ON......... AT LAST UNTIL Z COMES N TIMES...............  3
a=0; b=(a=0)?2:3; a) What will be the value of b? why b) If in 1st stmt a=0 is replaced by -1, b=? c) If in second stmt a=0 is replaced by -1, b=? Geometric-Software6
what is call by value and call by reference  2
Write a program to exchange two variaables without temp Geometric-Software6
pgm to find middle element of linklist(in efficent manner) Huawei2
what is the return value (status code) of exit() function.... what the arguments(integer value) passed to it means.... TCS1
what is the difference between #include<stdio.h> and #include "stdio.h" ?  2
how to estimate the disk access time? e.g. the time between read one byte and another byte in the disk. Google3
Is there any restriction in how many arguments printf or scanf function can take? in which file in my c++ compiler i can see the code for implementation of these two functions??  3
What is the difference between char a[] = "string"; and char *p = "string"; ? Honeywell11
what about "char *(*(*a[])())();" Oracle2
main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); } ME3
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com