How do I create a somaCum() function for Adian? C

Asked

Viewed 131 times

1

Angles ang = {0.0,46.0,91.2,134.7,179.2}, the unit is deg (steps). I have to implement code that initializes the values as a global array, and then defines the void somaCum(float arr[]){} function that computes the cumulative sums(Scum={S1,S2,S3,...,Sn}={X1,X1+X2,X1+X2+X3,...,X1+X2+...+ Xn} ) of each element, and write the values to the console . Present an example of usage (invoke function plus result in console).

float acc[]={0.0,46.0,91.2,134.7,179.2}
int accSize = 5;

void setup(){
 Serial.begin(9600);
 somaCum(acc);
}
void loop(){}
void somaCum(float acc[]){
 for(int n=0;n<accSize;n++){
  //Como é que faço a função?
}
  • Do you want to print the result of all the sums, or just the final sum? If it is the result of all sums, you just want to view the sums or you also want to store them in an array?

  • Result of all sums. Only visualize the sums. The statement of the question is this same.

1 answer

1

Only this here solves your problem friend?

void somaCum(float acc[]){
for(int n=0;n<accSize;n++){
float soma = acc[n] + acc[n-1];
Serial.print(soma);
  }
}
  • The rest of the code is fine?

  • I would have to change nothing else?

  • In theory yes, I can check later on my Alpha, but I think it does what you want, try to execute and have error q return

Browser other questions tagged

You are not signed in. Login or sign up in order to post.