Skip to content

Instantly share code, notes, and snippets.

View bixo-d's full-sized avatar

Rafael Aiquel Garbarini bixo-d

  • IDI-Orinoco
  • Ciudad Guayana
  • 02:51 (UTC -12:00)
View GitHub Profile
@bixo-d
bixo-d / movingAvg.c
Created July 13, 2022 00:45 — forked from bmccormack/movingAvg.c
Moving average example in C
#include <stdio.h>
int movingAvg(int *ptrArrNumbers, long *ptrSum, int pos, int len, int nextNum)
{
//Subtract the oldest number from the prev sum, add the new number
*ptrSum = *ptrSum - ptrArrNumbers[pos] + nextNum;
//Assign the nextNum to the position in the array
ptrArrNumbers[pos] = nextNum;
//return the average
return *ptrSum / len;