# Formula into C code...

Page 1 of 1

## 4 Replies - 3046 Views - Last Post: 11 September 2007 - 12:17 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=32997&amp;s=b01c95bc9d9e753aaa963aed372ecef3&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Daikide

Reputation: 0
• Posts: 16
• Joined: 20-August 07

# Formula into C code...

Posted 10 September 2007 - 10:53 AM

I need to put this formula : http://mathworld.wol...n/equation1.gif

Is This A Good Question/Topic? 0

## Replies To: Formula into C code...

### #2 MorphiusFaydal

• D.I.C Lover

Reputation: 43
• Posts: 1,376
• Joined: 12-May 05

## Re: Formula into C code...

Posted 10 September 2007 - 11:18 AM

http://www.le.ac.uk/cc/tutorials/c/

Should get you started.

### #3 NickDMax

Reputation: 2254
• Posts: 9,245
• Joined: 18-February 07

## Re: Formula into C code...

Posted 10 September 2007 - 12:49 PM

There is not a lot to. First off, you run though using a for-loop to calculate the average. Once you have the average you can then run though to sum up deviations. Then divide that sum by the number of samples.

pseudo-code for the first part:
```  data[] = {10, 23, 43, 34, 15, 24, 28, 13};
sum1=0;
for (x=0; x < 8; x++)
{
sum1 += data[x];
}
average = sum1/8;

```

The next part is basically the same thing.

### #4 Daikide

Reputation: 0
• Posts: 16
• Joined: 20-August 07

## Re: Formula into C code...

Posted 11 September 2007 - 02:05 AM

NickDMax, on 10 Sep, 2007 - 12:49 PM, said:

There is not a lot to. First off, you run though using a for-loop to calculate the average. Once you have the average you can then run though to sum up deviations. Then divide that sum by the number of samples.

pseudo-code for the first part:
```  data[] = {10, 23, 43, 34, 15, 24, 28, 13};
sum1=0;
for (x=0; x < 8; x++)
{
sum1 += data[x];
}
average = sum1/8;

```

The next part is basically the same thing.

Thanks man, you really helped me!

I don't need it for school or homework thingy... (we don't have a computing class at school )

LOL I actually nearly did it but I was too dum to finish it off by myself so I had it like this...

LOL DOn'T CRITESIZE, I JUST STARTED PROGRAMMING LOL: (IT'S BUGGY AS HELL)

main ()
{
} // <------------------- DELETE THIS TOO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

// TS2 - final timestamp
//TS1 - starting timestamp

//<-------DELETE THIS TO START EDITING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

string s;
file f; ///////
//int ts; //?
dyn_float A; ///////////
int sum;

fopen("")// Have to read in help. parameters here

while (1)
{
fgets (f, s);

while (feof(f)==0) ////////////

fscanf (s, "%d.%d.%d %d:%d:%d %f %f", year, month, day, hour, min, sec, setting, value);

ts = makeTime ( year, month, day, hour);

if (TS1 <ts < TS2) { // if (ts < ts_start) ...

dynAppend (A), value;
DebugN(A);

fclose(f); /////////////
break;
}

int N = 0;
x = value;

//sum =

//sum_2 =

sum = 0;

for (int i = 1; i <= dynlen (A);
i++)

{
sum += A[i];

}

sum = sum + x;
sum_2 = sum_2 + x*x;

int N = 0;

N = N + 1;

Mean = sum/N;

TV.text (Mean);

//Mean - Deviation

//the sum of "x"es /N i.e. x/N

///// dyn_array
////// fprint

///
if ((TS2 > TS1) || (TS2 = TS1)) { // Time Stamp Comparsion TEMP!

TV.text (" Wrong TS input");

Button.enabled = TRUE;

return 0;
}

////

// } // I need this here!

This post has been edited by Daikide: 11 September 2007 - 02:17 AM

### #5 MorphiusFaydal

• D.I.C Lover

Reputation: 43
• Posts: 1,376
• Joined: 12-May 05

## Re: Formula into C code...

Posted 11 September 2007 - 12:17 PM

When you're posting Code, put them in [ code][ /code] blocks... Without the space after the opening bracket. It's the little #-sign on the toolbar when you're making a post.