Question

using Arduino create a  program that calculates the average of the whole numbers from 1 to 500....

using Arduino create a  program that calculates the average of the whole numbers from 1 to 500. (Hint: use for)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//initializing variables

float total=0;
float average;

//setup function

void setup () {
}

//loop
void loop () {
    for(int i=1 ; i<=500 ; i++)//loop for taking 1 to 500 whole numbers
{
total=total+i; //finding sum of whole numbers
}
   average = total/500; //finding average of the whole numbers from 1 to 500

Serial.print("the average of whole numbers from 1 to 500 is : ");
Serial.print(average); // printing the result
}

OUTPUT

the average of whole numbers from 1 to 500 is : 250.500000

Add a comment
Know the answer?
Add Answer to:
using Arduino create a  program that calculates the average of the whole numbers from 1 to 500....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT