Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Fall 2012 IST 602

Raviteja Tatineni Homework # 1

CODE :

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main() //Main class starts { double[] temp = new double[70]; Random ran = new Random(); int m, n; // Filling values for (m = 0; m < temp.Length; m++) temp[m] = ran.Next(55, 99); // Displaying 10 weeks data n = 0; Console.WriteLine("10 weeks data "); foreach (double indx in temp)

{ Console.Write(indx + ","); ++n; if (n == 10) { Console.WriteLine(); n = 0; } } // to compute total average, highest and lowest of the total 70 days Console.WriteLine("\n\nThe average for 70 days is {0}. \n", avg(temp)); Console.WriteLine("The highest of 70 days is {0}. \n ", temp.Max()); Console.WriteLine("The lowest of 70 days is {0}. \n\n ", temp.Min()); // Compute and display weekly average double[] week = new double[7]; for (m = 0; m < (temp.Length / 7); m++) { Array.Copy(temp, m * 7, week, 0, 7); int i = 0; // to print weekly data Console.WriteLine("week {0} data:", m + 1); while (i < week.Length) { Console.Write(week[i] + ","); i++; } Console.WriteLine("\n\nThe lowest for week {0} is {1}", m + 1, week.Min()); Console.WriteLine("\nThe highest for week {0} is {1}", m + 1, week.Max()); Console.WriteLine("\nThe average for week {0} is {1}\n\n", m + 1, avg(week)); } Console.ReadKey(); } // to compute the average static double avg(double[] data) {

double tot = 0; foreach (double d in data) tot += d; return tot / data.Length; }

} }

You might also like