Nothing Special   »   [go: up one dir, main page]

Eme C#

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

using System;

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

namespace store_value_in_array
{
class Program
{
private static bool y;

static void Main(string[] args)


{
int i;
Console.Write("Input size of array: ");
int arrSize = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[arrSize];

//Assigning Value
for (i = 0; i < arrSize; i++)
{
Console.Write("Enter number: ");
arr[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("\n");
//Printing the value
for (i = 0; i < arrSize; i++)
{
Console.WriteLine("You Entered: {0}", arr[i]);
}

Console.WriteLine("\n");
//Get the sum of the elements
float sum = arr.Sum();

Console.WriteLine("Sum of the elements: " + sum);


Console.WriteLine();

//Get the total number or elements


int count = arr.Count();

//Get the smallest element


Console.WriteLine("Smallest Element: " + arr.Min());
Console.WriteLine();

//Get the largest value


Console.WriteLine("Largest Value: " + arr.Max());
Console.WriteLine();

Console.WriteLine("Total number of elements in the array: " + count);


Console.WriteLine();

//To get the avarage of the elements


float average = sum / count;

Console.WriteLine("Average of the elements: " + average);


//To roundoff
Console.WriteLine("RoundOff: " + Math.Round(average));

//To change the value of the elements in the array


//Specify the index number, for example you want to change the value from index 0

//Changing the value of all the elements in the array


for (i = 0; i < arrSize; i++)
{
Console.Write("Enter new value: ");
arr[i] = Convert.ToInt32(Console.ReadLine());
}
//Printing the value
for (i = 0; i < arrSize; i++)
{
Console.WriteLine("You entered: {0} ", +arr[i]);
}

Console.WriteLine();
Console.WriteLine("Do you want to display all the informaation of your array? y or n");
Console.Write("----- ");
string ans = Console.ReadLine();

if (ans == "y")
{
float Newsum = arr.Sum();

Console.WriteLine("Sum of the elements: " + Newsum);


Console.WriteLine();

//Get the total number or elements


int Newcount = arr.Count();

//Get the smallest element


Console.WriteLine("Smallest Element: " + arr.Min());
Console.WriteLine();

//Get the largest value


Console.WriteLine("Largest Value: " + arr.Max());
Console.WriteLine();

Console.WriteLine("Total number of elements in the array: " + Newcount);


Console.WriteLine();

//To get the avarage of the elements


float Newaverage = sum / count;

Console.WriteLine("Average of the elements: " + Newaverage);

//To roundoff
Console.WriteLine("RoundOff: " + Math.Round(Newaverage));
}
else
{
Console.WriteLine("THANK YOU FOR USING THE SYSTEM");
}
}
}
}

You might also like