Ok, It is all again back to to basics, by that i mean going back to doing baby steps. I am new to C#
but i will try my best to learn it and understand it better, hoping by the end of this quarter i will have a better understanding it. I finished doing the fibonacci number sequence and the code below shows how i did it, it may not be the best way of doing it but it works:
//This function calculates the fibonacci numbers
//and prints them individually
static void FibanaciNumbers(int num)
{
int prevNumber = 0;
int result = 0;
int tempResult = 0;
for(int i=0; i<= num; i++)
{
if (i == 1 == 2)
{
//In the fibonacci sequence the fibonacci number 2 and 3
// will always be 1, so for not wasting time we just check
//if the numbers are 2 and 3 we just assign our result and
//previus number variables to our.
prevNumber = 1;
result = 1;
tempResult = 1;
}
else
{
//we take the current prevNumber and add it to the result
//then take the sum and store it in a temporary variable
//then assign the result value to the previous and take
//the temporary result and assign it as our result. The result is
//our fibonacci number and we prints it out.
tempResult = prevNumber + result;
prevNumber = result;
result = tempResult;
}
//prints the number to the console
Console.WriteLine(" Fibonacci Number: " + result);
}
}
So long and stay thirst my firends.
but i will try my best to learn it and understand it better, hoping by the end of this quarter i will have a better understanding it. I finished doing the fibonacci number sequence and the code below shows how i did it, it may not be the best way of doing it but it works:
//This function calculates the fibonacci numbers
//and prints them individually
static void FibanaciNumbers(int num)
{
int prevNumber = 0;
int result = 0;
int tempResult = 0;
for(int i=0; i<= num; i++)
{
if (i == 1 == 2)
{
//In the fibonacci sequence the fibonacci number 2 and 3
// will always be 1, so for not wasting time we just check
//if the numbers are 2 and 3 we just assign our result and
//previus number variables to our.
prevNumber = 1;
result = 1;
tempResult = 1;
}
else
{
//we take the current prevNumber and add it to the result
//then take the sum and store it in a temporary variable
//then assign the result value to the previous and take
//the temporary result and assign it as our result. The result is
//our fibonacci number and we prints it out.
tempResult = prevNumber + result;
prevNumber = result;
result = tempResult;
}
//prints the number to the console
Console.WriteLine(" Fibonacci Number: " + result);
}
}
So long and stay thirst my firends.
Make sure you are using MSVisual studio 2010
ReplyDelete