Hi, how do you sort an array from the smallest number to the largest number?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
//declaring and intilizing variable
string myName = "";
int temp1 = 0;
float sum = 0;
double sumSqr = 0;
float average = (sum / 5);
double variance = 0;
//prompting the user for input.
Console.WriteLine("What is your name?");
myName = Console.ReadLine();
Console.WriteLine("Please enter a number between 10 and 50 five times: ");
int[] array1 = new int[5];
for (int i = 0; i < 5; i++)
{
temp1 = int.Parse(Console.ReadLine());
if (temp1 >= 10 && temp1 <= 50)
{
array1[i] = temp1;
}
else
{
Console.WriteLine("Your number is not between 10 and 50!\nPlease enter a number between 10 and 50: ");
i--;
}
}
for (int i = 0; i < 5; i++)
{
sum += array1[i];
}
average = sum / 5;
{
for (int i = 0; i < 5; i++)
{
sumSqr += Math.Pow((array1[i] - average), 2);
}
variance = sumSqr / 4;
}
Console.WriteLine("Average is {0}. ", average);
Console.WriteLine("Variance is {0}. ", variance);
Console.ReadKey();
}
}
}
No comments:
Post a Comment