0
Avg. Two number
3 Respostas
+ 5
I would use Zen's answer as it won't throw away any remainder. for example the average of 5 and 4 is 9/2 which is 4.5. Leslie's will output 4. Zen's will output 4.5. if you don't care for the remainder, Leslie's is fine.
you could also just cast Leslie's to a double by doing this: (double)(a+b)/2
+ 3
int a, b;
cin >> a >> b;
cout << (a + b)/2.0 << endl;
+ 2
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a; /*first number*/
cin >> b; /*second number*/
cout << (a+b)/2 << endl;
return 0;
}