The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How To Calculate krishna_sicsr Shell Programming and Scripting 3 03-21-2009 01:49 PM
calculating variance in perl programming cdfd123 Shell Programming and Scripting 4 01-15-2008 01:30 AM
calculate from three files koti_rama Shell Programming and Scripting 5 01-08-2008 09:27 AM
How to calculate with awk whatisthis Shell Programming and Scripting 4 11-09-2005 12:39 PM
bc calculate problem Nicol UNIX for Dummies Questions & Answers 2 09-13-2004 11:21 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 01-08-2008
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
Post C language to calculate mean,variance

Here I want to calculate mean,variance and sum from a file
1.1*2*4*22*211*22*12*22*22*11
2.2*2*22*12*22*11*11*122*33*22
3.9*7*22*88*87*98*67*66*56*66*11
As this is a large file and i am trying to write in c

where formulae of

MEAN = 1/N (X1...+..Xn)
Variance = square root of 1/N-1 (X1+.,,Xn - mean)2

So simply question say in this example we have one file where first part want to calculate mean and variance
again second part calculate mean and variance ..respectively and save the result

#include <math.h>
void moment(float data[], int n, float *ave, float *var)

{
void nrerror(char error_text[]);
int j;
float ep=0.0,s,p;
if (n <= 1) nrerror("n must be at least 2 in moment");

s=0.0;
for (j=1;j<=n;j++) s += data[j];
*ave=s/n;

what will be the code for variance?
Can rewrite the program with mentioning of open file and closing of file
Thanks
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0