# Perfect square in fibonacci sequence program not working

Page 1 of 1

## 1 Replies - 940 Views - Last Post: 18 November 2012 - 09:15 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=300734&amp;s=83cfb9cc33546869945b44c8b62a6050&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 hey92

Reputation: 0
• Posts: 28
• Joined: 07-November 11

# Perfect square in fibonacci sequence program not working

Posted 18 November 2012 - 06:46 PM

"Create a program to find out the first perfect square greater than 1 to occur in the Fibonacci sequence and display it to the console." I have no output when I enter an input.

```
#include <stdio.h>
#include <math.h>

int PerfectSquare(int n);
int Fibonacci(int n);

main()
{
int i;
int number=0;

int fibNumber=0;
int psNumber=0;

printf("Enter fibonacci number:");
scanf("%i",&number);

fibNumber = Fibonacci(number);

psNumber = PerfectSquare(fibNumber);

if(psNumber != 0){
printf("%i\n",psNumber);
}
}

int PerfectSquare(int n)
{

float root = sqrt(n);
if (n == ((int) root)*((int) root))
return root;
else
return 0;
}

int Fibonacci(int n){
if (n==0) return 0;
if (n==1) return 1;
return( Fibonacci(n-1)+Fibonacci(n-2) );
}

```

Is This A Good Question/Topic? 0

## Replies To: Perfect square in fibonacci sequence program not working

### #2 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,440
• Joined: 14-September 12

## Re: Perfect square in fibonacci sequence program not working

Posted 18 November 2012 - 09:15 PM

hey92, on 19 November 2012 - 07:16 AM, said:

```
int PerfectSquare(int n)
{

float root = sqrt(n);
if (n == ((int) root)*((int) root))
return root;
else
return 0;
}

```

Can you please explain what you are trying to do here?

The reason for you not getting any output probably lies in this very part.

regards,
Raghav

This post has been edited by raghav.naganathan: 18 November 2012 - 09:16 PM