68 464
Assignments Done
98,6%
Successfully Done
In December 2018

# Answer to Question #60001 in C# for josa

Question #60001
1) Receive a number and determine whether it is odd or even.
2) Obtain two numbers from the keyboard, and determine and display which (if either) is the larger of the two numbers.
3) Receive 3 numbers and display them in ascending order from smallest to largest
4) Add the numbers from 1 to 100 and display the sum
5) Add the even numbers between 0 and any positive integer number given by the user.
6) Find the average of two numbers given by the user.
7) Find the average, maximum, minimum, and sum of three numbers given by the user.
// 1) Receive a number and determine whether it is odd or even.
Console.Write("Enter a number : ");
// odd check
if ((a % 2) == 0)
Console.WriteLine(a.ToString() + " - even number");
else
Console.WriteLine(a.ToString() + " - odd number");
// 2) Obtain two numbers from the keyboard, and determine and display which (if either) is the larger of the two numbers.
Console.Write("Enter number 1 : ");
Console.Write("Enter number 2 : ");
// comparison
if (n1 > n2)
Console.WriteLine("{0} is greater than {1} ", n1, n2);
else if (n1 < n2)
Console.WriteLine("{0} is less than {1} ", n1, n2);
else
Console.WriteLine("{0} is equal to {1} ", n1, n2);
//3) Receive 3 numbers and display them in ascending order from smallest to largest
int[] mas = new int[3];
for (int i = 0; i < 3; i++)
{
Console.Write("Enter number " + (i + 1).ToString() + " : ");
}
// sorting
Array.Sort(mas);
Console.Write("Numbers in ascending order : ");
foreach (int number in mas)
Console.Write(number.ToString() + " ");
//4) Add the numbers from 1 to 100 and display the sum
int sum = 0;
for (int i = 1; i <= 100; i++)
sum += i;
Console.WriteLine("Sum of numbers from 1 to 100 : " + sum.ToString());
//5) Add the even numbers between 0 and any positive integer number given by the user.
Console.Write("Enter any positive integer number : ");
int sum = 0;
for (int i = 0; i < max; i = i + 2)
sum += i;
Console.WriteLine("Sum of even numbers between 0 and {0} : {1}", max, sum);

//6) Find the average of two numbers given by the user.
Console.Write("Enter number 1 : ");
Console.Write("Enter number 2 : ");
double average = (n1 + n2) / 2;
Console.WriteLine("Average of {0} and {1} : {2} ", n1, n2, average);
//7) Find the average, maximum, minimum, and sum of three numbers given by the user.
double[] mas = new double[3];
for (int i = 0; i < 3; i++)
{
Console.Write("Enter number " + (i + 1).ToString() + " : ");
}
double max = mas.Max();
double min = mas.Min();
double sum = mas.Sum();
double average = mas.Average();
Console.WriteLine("Average = {0} ; maximum = {1} ; minimum = {2} ; sum = {3} ", average, max, min, sum);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!