coding for Fibonacci.?

Answer Posted / siggi

class hcl
{
public static void main(String arg[])
{int a=0;
int b=1;
int i=1;
int x,y;

/*System.out.println("enter the no.");*/
x=Integer.parseInt(arg[0]);
if(x==0 || x==1)
{ System.out.println("yes it is");}

else {

do
{
y=a+b;
if(x==y)
{ System.out.println("yes it is");
i=0;}
else if(x>y)
{a=b;
b=y;}
else
{ i=0;
System.out.println("no it is not");}

}while(i!=0);

}
}
}

Is This Answer Correct ?    1 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a code to generate a series where the next element is the sum of last k terms.

971


Explain what is meant by 'bit masking'?

870


A banker has a seif with a cipher. Not to forget the cipher, he wants to write it coded as following: each digit to be replaced with the difference of 9 with the current digit. The banker chose a cipher. Decipher it knowing the cipher starts with a digit different than 9. I need to write a program that takes the cipher from the keyboard and prints the new cipher. I thought of the following: Take the input from the keyboard and put it into a string or an array. Go through the object with a for and for each digit other than the first, substract it from 9 and add it to another variable. Print the new variable. Theoretically I thought of it but I don't know much C. Could you give me any kind of hint, whether I am on the right track or not?

1734


What are the different types of constants?

830


What is the use of gets and puts?

771


what is a constant pointer in C

878


Why is C language being considered a middle level language?

843


Explain what is dynamic data structure?

872


write a proram to reverse the string using switch case?

2677


in iso what are the common technological language?

1851


What are header files and explain what are its uses in c programming?

835


Where static variables are stored in memory in c?

718


What does 4d mean in c?

1220


How to throw some light on the b tree?

809


Discuss the function of conditional operator, size of operator and comma operator with examples.

884