Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

solve fizzbuz c#

// if you don't know what FizzBuzz is than read the next lines

// FizzBuzz is one of the most famous programming 
// problems to solve for exercise.
// the user inputs a number and
// if the number is devided by 3 and has no remainder left print Fizz.
// if the number is devided by 5 and has no remainder left print Buzz.
// if the number is devided by both and has no remainder left print FizzBuzz.
// if it does have a remainder print the number

static string FizzBuzz(int n)
{
	if (n % 3 == 0 && n % 5 == 0)
    {
        return "FizzBuzz";
    }
    else if (n % 5 == 0)
    {
        return "Buzz";
    }
    else if (n % 3 == 0)
    {
        return "Fizz"
    }
    else 
    {
    	return num.ToString();
    }
}

// wait before closing
Console.ReadKey();
 
PREVIOUS NEXT
Tagged: #solve #fizzbuz
ADD COMMENT
Topic
Name
3+4 =