Write a C# program to check whether a given substring is present in the given string

Write C# Program to Find the Average Values of all the Array Elements

Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

using System;
class Program
{
    public void sumAverageElements(int[] arr, int size)
    {
 
        int sum = 0;
        int average = 0;
        for (int i = 0; i < size; i++)
        {
            sum += arr[i];
        }
        average = sum / size;
        Console.WriteLine("Sum Of Array is : " + sum);
        Console.WriteLine("Average Of Array is : " + average);
        Console.ReadLine();
    }
    public static void Main(string[] args)
    {
        int size;
        Console.WriteLine("Enter the Size :");
        size = Convert.ToInt32(Console.ReadLine());
        int[] a = new int[size];
        Console.WriteLine("Enter the Elements of the Array : ");
        for (int i = 0; i < size; i++)
        {
            a[i] = Convert.ToInt32(Console.ReadLine());
        }
        int len = a.Length;
        Program p = new Program();
        p.sumAverageElements(a, len);
    }
 
}

Result

Write C# Program to Find the Average Values of all the Array Elements
Write C# Program to Find the Average Values of all the Array Elements

Add a Comment

Your email address will not be published. Required fields are marked *