Write a function that receives 5 integers and returns the sum, average and standard deviation of these numbers. C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication17
{
class Program
{
static void Main(string[] args)
{
int a, b, c, d, e;
Console.WriteLine("enter first number");
a = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("enter second number");
b = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("enter third number");
c = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("enter forth number");
d = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("enter fifth number");
e = Convert.ToInt16(Console.ReadLine());
Program p = new Program();
int f = p.sum(a, b, c, d, e);
int g = p.average(f);
double h = p.standard_deviation(a, b, c, d, e, f, g);
Console.WriteLine("sum of numbers are="+f);
Console.WriteLine("averge of numbers are="+g);
Console.WriteLine("stardard derivation of numbers is="+h);
}
private double standard_deviation(int a, int b, int c, int d, int e, int f, int g)
{
double i, j, k, l, m,deri,squ;
i = a - g;
j = b - g;
k = c - g;
l = d - g;
m = e - g;
i = Math.Pow(i, 2);
j = Math.Pow(j, 2);
k = Math.Pow(k, 2);
l = Math.Pow(l, 2);
m = Math.Pow(m, 2);
deri = (i + j + k + l + m) / g;
squ = Math.Sqrt(deri);
return squ;
}
private int average(int f)
{
int avg = f / 5;
return avg;
}
private int sum(int a, int b, int c, int d, int e)
{
int sum = a + b + c + d + e;
return sum;
}
}
}
Comments
Post a Comment