After doing homework 2, my team and i started working the next assignment for unit testing i know it it going to be interesting, believe it or not the idea of unity testing is new to me, but dont getting wrong i am willing to learn this stuff in and out. Hopefuly i will be able to use this skill from now untill i cant code anymore god knows when.
So long and stay thirst my friends..
Monday, January 23, 2012
Thursday, January 12, 2012
Fibonacci Homework
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.
Subscribe to:
Posts (Atom)