average calulator code example
Example 1: average calculator
1. make an array nums[number of neumbers you will calculate the average of]
wich will store the numbers and a variable sum=0 (make it double)
2. input that array with a loop
3. in the loop, after you have entered nums[i] add it to sum
4. after loop output sum divided by the number of numbers
code in c++:
#include <iostream>
using namespace std;
int main()
{
long long nums[ 5 ]; // I used 5 cus I like the number 5.
//Could have been 3 or 10 or whatever.
double sum = 0;
for( long long i = 1 ; i <= 5 ; i++ )
{
cin >> nums[ i ];
sum += nums[ i ];
}
cout << sum / 5 << endl ;
return 0;
}
Example 2: Calculation of Average
This program is to calculate the average of two numbers.
The numbers are 3 and 5.
The average is: 4.0