# Does anyone know C?



## Brian (Mar 14, 2006)

Does anyone know how to program in "C" language?


----------



## Ciddian (Mar 15, 2006)

Oohh good heavens.. No i dont  Bf used too.... 

But its been years.. Sorry brian


----------



## Pablo (Mar 27, 2006)

I took the class in high school... sat through three classes... understood nothing... Dropped the course... :S


----------



## Thistle (Jun 4, 2006)

Sowry, I'm struggling to learn C#.


----------



## holocron (Mar 12, 2006)

what do you need to know? It's been a few years, but I might remember.


----------



## Brian (Mar 14, 2006)

I cant this stuff to work properly!

It is an assignment due for my comp science class, I don't even know why they are making us take C for a biology major... retards.

The Fibonacci sequence is a series of whole numbers starting at 1, followed by the sum of 
the two preceding numbers. The first eight ones are 1, 1, 2, 3, 5, 8, 13 and 21.

Write one C program that will accomplish all the following tasks:

a) Display the complete Fibonacci sequence until you reach a value less or equal than 
1,000,000 (one million). Your program will also display how many numbers are 
there in that sequence. For example, if the value is less or equal than 25 (as shown above), 
there are 8 numbers in the sequence.

b) Display all the numbers (if any) that are part of the Fibonacci sequence below 1,000,000
and whose square root is a whole number. For example 16 has a whole square root (4), but 16 
is not part of the Fibonacci sequence. Also display how many numbers satisfy these two 
conditions (part of Fibonacci below 1,000,000 and whole square root).

c) Part b) *must* be done with the help of a function called "whole" that you will write. 
The "whole" function will accept one real (double) number and will return 1 if it is a 
whole number and 0 if not. For example whole(11.0) would be 1, and whole(1.5) would be 0.

So far, my code is:

include <stdio.h>
int
main (void)

{
int a = 1;
int b = 0;
int value;
int i;

printf("Please enter a number that will act as a sentinel for the Fibonacci sequence - this number must be less than or equal to 1,000,000\n");
scanf("%d", &value);

if(value <= 1000000)
{

while (a <= value && b <= value)
{
printf("%d\n", a);
b+= a;
printf("%d\n", b);
a+= b;
}
}
else
printf("The number acting as a sentinel must be less than or equal to 1,000,000");

printf("%d", i);

}


----------



## holocron (Mar 12, 2006)

it would help if you pasted the debug code.

You need another var. I'm not going to give it away, but it's something like:

int a = 1, b = 1;
while ( b < value ) {
int c = a + b;
a = b;
b = c;
} 

you need the third var to store the calculated values and you need to keep updating b and a with the older fib vals.

Hope that helps.


----------

