Exam # 2 Page 4 (a) Write a method that accepts two integer parameters. The meth
ID: 3706186 • Letter: E
Question
Exam # 2 Page 4 (a) Write a method that accepts two integer parameters. The metho returns the average of the square roots of all the integers and the second. [For example: if the parameters are 3 and 7, then computes between the first the function (b) Write a main method that will read a number to be used as a count followed by "count" pairs. (For example, a 5 may be followed by 5 pairs of numbers). The function will print each pair read along with the average of square roots of the integers between the first and the second (calculated by calling the function above) 201Explanation / Answer
a)
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
double squareroot_avg(int a,int b){
double avg=0;
for(int i=a;i<=b;i++){
avg+= sqrt(i);
}
avg = avg/abs(b-a);
return avg;
}
int main()
{
int a,b;
cout<<"Enter a and b ";
cin>>a;
cin>>b;
double avg = squareroot_avg(a,b);
cout<<avg;
return 0;
}
b)
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
void squareroot_avg(int a){
for(int k=0;k<a;k++){
int a,b;
cout<<"Enter a and b ";
cin>>a;
cin>>b;
double avg=0;
for(int i=a;i<=b;i++){
avg+= sqrt(i);
}
avg = avg/abs(b-a);
cout<<avg<<endl;
}
}
int main()
{
int count;
cout<<"Enter count pairs ";
cin>>count;
squareroot_avg(count);
return 0;
}
//comment if you want in another programming language :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.