Input all the expenditure of 4 weeks and find min, max and average expense. in c#
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cp_theory_task_paractise
{
class Program
{
static void Main(string[] args)
{
int min = 0, max = 0, avg = 0, n,exp,texp=0;
Console.WriteLine("Enter no of weeks");
n = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
Console.WriteLine("Enter Expenses of week {0}",i);
exp = Convert.ToInt32(Console.ReadLine());
if (i == 1)
{
max = exp;
min = exp;
}
if (max<exp)
{
max = exp;
}
if (min>exp)
{
min = exp;
}
texp = texp + exp;
}
avg = texp / n;
Console.WriteLine("Maximum expences:{0}", max);
Console.WriteLine("Minimum expences:{0}", min);
Console.WriteLine("Averrage expences:{0}", avg);
}
}
}
Comments
Post a Comment