I need to write a program that finds the biggest number from given 3 numbers and print the result on the console in C#.

How can I do it?

retagged

+1 vote

Try this code out:

```using System;

class BiggestNumber
{
static void Main()
{

if (a > b && a > c)
{
Console.WriteLine("The biggest number is: {0}", a);
}
else if (b > a && b > c)
{
Console.WriteLine("The biggest number is: {0}", b);
}
else
{
Console.WriteLine("The biggest number is: {0}", c);
}
}
}```
edited by user golearnweb
+1 vote

```using System;

class BigNumber
{
static void Main()
{

if (a > b)
{
if (a > c)
{
Console.WriteLine("The biggest number is: {0}", a);
}
else
{
Console.WriteLine("The biggest number is: {0}", c);
}
}
else
{
if (b > c)
{
Console.WriteLine("The biggest number is: {0}", b);
}
else
{
Console.WriteLine("The biggest number is: {0}", c);
}
}
}
}```
edited by user golearnweb
+1 vote

You must be careful with the numerical data type! For example if you have an output like this:

 a b c biggest 5 2 2 5 -2 -2 1 1 -2 4 3 4 0 -2.5 5 5 -0.1 -0.5 -1.1 -0.1

Then you must use double (or decimal) instead of integer... Like this:

```using System;

class TheBiggestOfThreeNumbers
{
static void Main()
{

if (a>b && a>c)
{
Console.WriteLine("The biggest number is: " + a);
}
else if (b>a && b>c)
{
Console.WriteLine("The biggest number is: " + b);
}
else
{
Console.WriteLine("The biggest number is: " + c);
}
}
}```
edited by user golearnweb
Or like this:
using System;

namespace TheBiggestOfThreeNumbers
{
class TheBiggestOfThreeNumbers
{
static void Main()
{

if (a > b)
{
if (a > c)
{
Console.WriteLine("{0}", a);
}
}
else if (b > a)
{
if (b > c)
{
Console.WriteLine("{0}", b);
}
}
else if (c > a)
{
if (c > b)
{
Console.WriteLine("{0}", c);
}
}
}
}
}

After you have the numbers - you can put them in an array (first make sure you have this line in the beginning of the code: using System.Linq;) - and then to use one of the functions of the array - .Min (or in this case .Max)  - easy and very useful!

The code:

```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

{
static void Main()
{