Hi xXMADEXx,
Try this code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
public static void PrintIndexAndValues(int[] myArr)
{
for (int i = 0; i < myArr.Length; i++)
{
Console.WriteLine(" [{0}] : {1}", i, myArr[i]);
}
Console.WriteLine();
}
static void Main(string[] args)
{
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;
}
Array.Sort(array1);
Console.WriteLine("Sort the array from the smallest number to the largest number:");
PrintIndexAndValues(array1);
Console.WriteLine("Average is {0}. ", average);
Console.WriteLine("Variance is {0}. ", variance);
Console.ReadKey();
}
}
}
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
No comments:
Post a Comment