
-----------------------------------
marie85
Tue Oct 31, 2006 8:51 pm

Help with square root function (in C)
-----------------------------------
Hi,

I'm new to ComSci.ca but have been reading here for quite a while. I'm also a bit new to the world of computer science(not professional level yet though, still in HS lol) and there are many things that I have me a little confused.

Well, I'm doing some excersice programs, and I need to write a function that will display all the numbers of the fibonaci sequence that are smaller than 500 and have a whole sqare root. Also, the function must display how many numbers have a whole square root (so, if only 1 number has a whole square root then display "1").


I'm trying my best to understand all this, but I seem to be having lots of problems with programming. I'll keep trying, and I hope you guys can help me out here. Thanks you so much in advance

-----------------------------------
Andy
Tue Oct 31, 2006 9:32 pm


-----------------------------------
Welcome! the hardest thing i find about CS is how to break the problem down into smaller solvable pieces.

I digress

You probably know how to, write a program that will generate the fibonacci sequence.

So write a functio nthat will test whether if a number is a perfect square.

then simply run the function on each of the element of the sequence, and add 1 to a counter if your function returns true.

wrap everything up in a for loop of 500, and you're done!

If you need more help, post some of your attempts so we can give you proper guidelines.

-----------------------------------
marie85
Tue Oct 31, 2006 9:51 pm


-----------------------------------
This is what I've been trying to do, but it doesn't seem to work when I include it in the program


whole (int f);

{
int x=0,y=1, f;

      for (f= 0; f nat*nat then
    tmp = fib1 + fib2, fib1 = fib2, fib2 = tmp
  else if nat*nat > fib2 then
    nat += 1
  else if nat * nat = fib2 then
    output fib2 + "is a perfect suare, and is the " + count + " number in the fib. squence"


-----------------------------------
md
Tue Oct 31, 2006 10:39 pm


-----------------------------------
[edit type followup] replace n in the loop with count, and make the >'s <
