Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to do fizzbuzz in 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();
Comment

PREVIOUS NEXT
Code Example
Csharp :: nginx listen on 80 and 443 
Csharp :: .net core authorizationhandlercontext 
Csharp :: blazor alert 
Csharp :: how to check if control key is pressed c# 
Csharp :: c# list get element from end 
Csharp :: cshtml foreach 
Csharp :: learn c# 
Csharp :: convert dto to dictionary c# 
Csharp :: c# datetimepicker set weeks before today 
Csharp :: c# get all class properties 
Csharp :: round double c# 
Csharp :: unity hub black screen 
Csharp :: c# console beep sounds 
Csharp :: what is data encapsulation c# 
Csharp :: c# method summary new line 
Csharp :: c# getforegroundwindow 
Csharp :: unity json save array 
Csharp :: video gets pixelated unity 
Csharp :: remove carriage returns from string c# 
Csharp :: instantiate iqueryable c# 
Csharp :: unity button press onclick click add C# 
Csharp :: call function from another script unity 
Csharp :: casting string to enum type 
Csharp :: trigger collider unity 
Csharp :: c# create dynamic object 
Csharp :: hashing a file in C# 
Csharp :: swaggergen add service not getting info in .net core 
Csharp :: unity movement 
Csharp :: c# multiply string 
Csharp :: how to remove all buttons on a form C# 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =