using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace array
{
class Program
{
public int sum( int []x)
{
int sum = 0;
for (int i = 0; i < x.Length; i++)
{
sum = sum + x[i];
}
return sum;
}
public int findmax(int []x)
{
int max=x[0];
for (int i = 1; i < x.Length; i++)
{
if (max<=x[i])
{
max = x[i];
}
}
return max;
}
public int findmin(int[] x)
{
int min = x[0];
for (int i = 1; i < x.Length; i++)
{
if (min >= x[i])
{
min = x[i];
}
}
return min;
}
static void Main(string[] args)
{
int[] a = new int[] { 10, 20, 30,50,100 };
Program p = new Program();
int v = p.sum(a);
Console.WriteLine("sum of array is : "+v);
Console.WriteLine("max number is "+p.findmax(a));
Console.WriteLine("min number is " + p.findmin(a));
Console.ReadLine();
}
}
}
No comments:
Post a Comment