Breaking News

Tuesday, 24 July 2018

Write a class called Calculations, which has a static method called average, which takes a one dimensional array for double type as parameter, and prints the average of the array Elements.

Write a class called Calculations, which has a static method called average, which takes aone dimensional array for double type as parameter, and prints the average of the arrayElements.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tutorial3
{
   class Calculation
   {
       static void avg(double[] arr)
       {
           double sum = 0;
         
           foreach (double  i in arr)
           {
               sum += i;
           }
           Console.WriteLine("Sum is...." + sum );
           Console.WriteLine("Avg is...." + (sum / arr.Length));
       }
       public void start()
       {
           int i;
           Console.Write("Enter size of arry....");
           int n = int.Parse(Console.ReadLine());
           double[] ar = new double[n];
           for (i = 0; i < n; i++)
           {
               Console.Write("Enter " + i + " Element....");
               ar[i] = double.Parse(Console.ReadLine());
           }
           Calculation.avg(ar);
       }
   }
}

Output:-


No comments:

Post a Comment