954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

computation moving average

Greetings all.
I need help to create a c program for computation of moving average.

anurag awasthi
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

A moving average would look like this:
Average = 0.0 (Use doubles)
Number of elements = 0.0
Total = 0.0
While there are more numbers:
Ask for a new number.
Add new number to total.
Add 1 to number of elements.
Divide total by number of elements.
Store in average.
Loop

And here is a lovely snippet of code for you to get you started.

#include <stdio.h>
int main(){
    double average=0;
    double sum=0;
    double entry;
    char keepGoing='y';
    while(keepGoing=='y'){
        printf("Please input your value: ");
        http://www.cplusplus.com/reference/clibrary/cstdio/fscanf/

        // Do something awesome.

        printf("Keep going?");
        //http://www.cplusplus.com/reference/clibrary/cstdio/fscanf/
    }
    return 0;
}
DeanMSands3
Junior Poster
185 posts since Jan 2012
Reputation Points: 37
Solved Threads: 26
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: