Welcome, Guest: Join Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,715,539 members, 6,418,340 topics. Date: Tuesday, 03 August 2021 at 03:28 AM

Help With C# Code - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help With C# Code (2115 Views)

Why You Should Start Programming With C. / Finger Print Application With C# / Help On How A Make An App A Trial Version With C# (2) (3) (4)

(1) (Reply) (Go Down)

Help With C# Code by milanseedorf(m): 12:34pm On Jun 20, 2011
hi is there any guru programmer in c# that can help me with codes for calculating mean, median and mode of numbers.
Re: Help With C# Code by Nobody: 12:49pm On Jun 20, 2011
You do not need a guru programmer for this task, an [i]i[/i]diot programmer would do!
Re: Help With C# Code by Fayimora(m): 3:05pm On Jun 20, 2011
What have you come up with? At least you should have done something so where are your codes that "aren't working"
Re: Help With C# Code by SGN(m): 10:30am On Jun 21, 2011
@Fayimora is right, you should at least try something first and then guys here could help you finetune, and @omo_to_dun is also right, what you are trying to achieve is not exactly rocket science. But in case you really are pressed for time, or unable to fathom something on your own, a quick yahoo or google search can help you (sometime, it pays not to reinvent the wheels).

I find this link, that seems to do what you want.
http://bytes.com/topic/c-sharp/answers/254401-anyone-have-mean-median-mode-stddev-routines-c

and the post and code itself is as follows:



Kyle Kaitan
Drebin:

This is untested, but feel free to use as you see fit. For more extensive
statistical/math computations like Bessel functions, likelihood estimators,
and so forth, you might want to check out NMath. I've favored readability
over raw speed here, but this should be very fast.

HTH,
- k^2

///// Begin code.
using System;
using System.Collections;

public class MathAverages
{
// Computes the median x~ of a set of values X. O(1) implementation,
public static float Median(float[] values)
{
int size = values.Length - 1;
return ((values[size/2] == values[size/2 + 1]) / 2);
}

// Computes the mode set x{} of a set of values X. O(n) implementation.
public static float[] Mode(float[] values)
{
Hashtable h = new Hashtable();
int count = 0;
foreach (float value in values)
{
h[value]++;
if (h[value] > count)
count = h[value];
}

ArrayList modeValues = new ArrayList();
foreach (DictionaryEntry e in h)
{
if (e.Value >= count) modeValues.Add(e.Key);
}

return (float[])modeValues.ToArray(typeof(System.Single));
}

// Computes the arithmetic mean x-bar of a set of values X. O(n)
implementation.
public static float Mean(float[] values)
{
float sum = 0;
foreach (float value in values)
{
sum += value;
}
return sum/(values.Length);
}
}
///// End code.
Re: Help With C# Code by Nobody: 3:16am On Jun 22, 2011
This is the problem that we have in Nigeria: instead of guiding the man on how to write the code, you handed it to him. How is he supposed to learn?
Re: Help With C# Code by milanseedorf(m): 12:36am On Jun 23, 2011
tanks soo much fayimora, omo to dun u learn wen someone gives you a way all the same tanks for the reply.
Re: Help With C# Code by Fayimora(m): 2:52pm On Jun 24, 2011
omo_to_dun:

This is the problem that we have in Nigeria: instead of guiding the man on how to write the code, you handed it to him. How is he supposed to learn?

I got tired of trying to point this out, No one listens!

(1) (Reply)

Thoughest Question To Answer. Even Top Coders May Fail. / 82 Free Tutorials In iOS & iPhone Programming Course For Beginners / Great Work guys

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2021 Oluwaseun Osewa. All rights reserved. See How To Advertise. 47
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.