For Loop- Solve a series

A simple example to demonstrate the use a looping constraints to solve mathematical expressions-


The Solution-


int x;
double sum,term;
sum=0;
for(x=1 ;x<=25 ;x+=3){
term= 1/x;
sum=sum+term;
}
Serial.println("The result is" + sum);

Note that this code can also be written in the form of a while or a do-while loop.

Comments