Use the following function:
/* returns the average of two real numbers */
double average (const double a, const double b) {
return a/2.0 + b/2.0;
}
Note that we do not use (a+b) / 2.0 because the expression a+b could overflow the range of a double. By dividing each value by 2 before summing we ensure the result can never overflow no matter how large a and b are.
Ideally, you should write separate functions to cater for float and long double arguments independently:
/* returns the average of two long doubles */
long double average_lng (const long double a, const long double b) { return a/2.0 + b/2.0;
}
/* returns the average of two floats */
float average_flt (const float a, const float b) {
return a/2.0F + b/2.0F;
}
For mixed-mode arithmetic, always use the highest precision argument. E.g., the average of a float and a double is a double, so use the function that returns a double, not a float. The float argument will be implicitly cast to a double.
double getAverage(const double a, const double b) { return (a + b)/2.0;}
Right angles are always 90 degrees. There is no need to calculate this; an angle is either 90 degrees or it is not. The following inline function is all you really need: inline const bool IsRightAngle(double angle) { return(angle==90.0); }
Use sizeof( ).
True - A C++ constructor cannot return a value.
No. There is no default return type for functions, it must be explicitly specified in both the function declaration and in the definition. To specify no return value, return void. To return a variant type, return void* (pointer to void). Otherwise return the exact type.
You can't, you have to come up with variables to calculate grades
6.38 is the average of the three numbers.
Just add the numbers, and divide the result by 3 (since there are 3 numbers).
do something
The mean of a set of numbers is the average. That is to say, all the numbers added together and divided by the number of the numbers. the answer is 30.5
cn = c0 *( 1 + i ) pow n
The average is all the numbers added together and then divided by the # of numbers.(80+85+90+88+86+83+89+70)/8=671/8=83.875Order of operations has the brackets first and then the division.
The average is the sum divided by the number of original numbers. The sum of 132, 140, and 145 is 417. There were three original numbers, so the average is one-third of 417 or 139
2.5 + 3 + 4 = 9.5 then divide by 3 (the number of numbers) = 3.167
1 plus 2 plus 3 plus 4 equal 10. 10 times 5 equals 50.
We have the resources to calculate the answer to that example, and we know how to use them. Tell us how such unusual numbers arose, and how the answer will help you in your work, and we'll put our staff to work to find it for you.
int main() { int num1; int num2; int result = num1 + num2; return 0; }
#include <iostream> using namespace std; int main() { double num1, num2, avg, sum; //use double instead of int because int only recognize whole numbers cout<<"Enter a number: "; cin>>num1; cout<<"Enter a number: "; cin>>num2; sum=num1+num2; avg=sum/2 cout<<" The average is: "<<avg; system("pause"); return 0; }