User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

Begin8. Two numbers \(a\) and \(b\) are given. Find their arithmetic mean: \((a + b)/2\).

Solution in Python 3:

import random

a = random.randrange(1,10)
b = random.randrange(1,10)
print("a = ", a)
print("b = ", b)
print("Arithmetic mean: ", (a+b)/2)

Solution in C++:

#include<iostream>
using namespace std;
int main(){
double a,b,c;
cout << "Enter number a: ";
cin >> a;
cout << "Enter number b: ";
cin >> b;
c = (a+b)/2;
cout << "Arithmetic mean: " << c;
return 0;
}