Question

In: Computer Science

SumOfTwoHighest returns the sum of the two largest numbers SumOfTwoHighest(1,2,3) ➔ 5 SumOfTwoHighest(0,1,0) ➔ 1 SumOfTwoHighest(-1,-2,-3)...

SumOfTwoHighest returns the sum of the two largest numbers
SumOfTwoHighest(1,2,3) ➔ 5
SumOfTwoHighest(0,1,0) ➔ 1
SumOfTwoHighest(-1,-2,-3) ➔ -5

int SumOfTwoHighest(int i, int j, int k)
{
}

#include <iostream>

using namespace std;

int SumOf3Digits(double d)

{

string s = to_string(d);

int sum=0;

for(int i=0;i<s.size();i++)

{

if(s[i]!='.')sum= sum+ s[i]-'0';

}

return sum;

}

int max(int i, int j)

{

return i>j? i:j;

}

int Power(double d, int pow = 2)
{
if(pow == 0)
return 1;
if(pow == 1)
return d;
if(pow == 2)
return d*d;
return d*d*d;
  
}

nt main() {

cout<<SumOf3Digits(5.13)<<endl;

cout<<max(5,3);

cout << power(6.3,0)

cout << SumOfTwoHighest

return 0;

}

Solutions

Expert Solution

OUTPUT

CODE TO COPY

#include <iostream>
using namespace std;

int SumOfTwoHighest(int i, int j, int k)
{
int temp;
if(i > j)
{
temp = i;
i = j;
j = temp;
}
if(i > k)
{
temp = i;
i = k;
k = temp;
}
  
if(j > k)
{
temp = k;
k = j;
j = temp;
}
  
return j+k;
}


int main() {
cout << SumOfTwoHighest(1, 2, 3) << endl;
cout << SumOfTwoHighest(0, 1, 0) << endl;
cout << SumOfTwoHighest(-1, -2, -3) << endl;
}

PLEASE UP VOTE


Related Solutions

The sum of two numbers is 34. a)Find the largest possible product of these numbers.
  1-The sum of two numbers is 34.    a)Find the largest possible product of these numbers.    b)What would be the largest possible product if the sum if the two numbers were "k"? 2-Sixty meters of fencing are used to fence a rectangular garden.    a)Find the dimensions that will give that maximum area.    b)What would be the maximum area if "k" feet of fencing were used in terms of "k"? THANK YOU
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them
create two random numbers between 1 and 6. if when the sum of two numbers are...
create two random numbers between 1 and 6. if when the sum of two numbers are added togethere their sum is less than 5 or greater than 12, output to the console: "you win". if is not, output "you lose" C++
Write a function called alter_sum(n)that returns the alternating sum of all the numbers from 1 to...
Write a function called alter_sum(n)that returns the alternating sum of all the numbers from 1 to n so that the first number is added, the second number is subtracted, the third number added, the fourth subtracted, and so on: 1-2+3-4+5-6+7… until you reach n. If n is 0 or less then return 0.
The sum of two numbers is 35 and their difference is 13. Find the numbers?
The sum  of two numbers is 35 and their difference is 13. Find the numbers?
Monthly returns for two stocks are given below: Month 1 2 3 4 5 6 7...
Monthly returns for two stocks are given below: Month 1 2 3 4 5 6 7 8 9 10 11 12 rA 4.10% 1.12% 1.66% −0.18% −4.71% −0.60% −0.91% 1.02% 1.69% −0.51% 1.42% 2.52% rB −3.36% −1.93% −0.45% 0.34% 4.27% 8.48% 1.86% 4.10% 6.41% −5.24% −1.06% 1.40% (a) Calculate the correlation between the returns of these two stocks. Consider a portfolio of the two stocks weighted 60:40 at t = 0. (b) Calculate the returns on the rebalanced portfolio for...
Four cards bearing the numbers 2, 3, 4 and 5 are placed on the table. Two...
Four cards bearing the numbers 2, 3, 4 and 5 are placed on the table. Two cards are selected from these four cards to form a two-digit number. List the sample space. Find the probability that the number formed a) Is divisible by 3. b) Is greater than 33 c) Is a multiple of 11 d) Is less than 55.
EXAMPLE 5: FINDING THE SUM AND DIFFERENCE OF TWO 3 X 3 MATRICES
Given A and BMath output errorBBFind the sum.Find the difference. Math output errorA=\left[\begin{array}{rrr}\qquad 2& \qquad -10& \qquad -2\\ \qquad 14& \qquad 12& \qquad 10\\ \qquad 4& \qquad -2& \qquad 2\end{array}\right]\text{ and }B=\left[\begin{array}{rrr}\qquad 6& \qquad 10& \qquad -2\\ \qquad 0& \qquad -12& \qquad -4\\ \qquad -5& \qquad 2& \qquad -2\end{array}\right]A=⎣⎡​2144​−1012−2​−2102​⎦⎤​ and B=⎣⎡​60−5​10−122​−2−4−2​⎦⎤​
Consider the set of integers A = {1, 2, 3, 4, 5}. Pairs of numbers are...
Consider the set of integers A = {1, 2, 3, 4, 5}. Pairs of numbers are constructed where each number of the pair comes from set A. Construct the sampling distribution of sample ranges. Apply the Empirical Rule to this distribution.
def sum_gt_avg(num_list): Implement a function that returns the sum of the numbers in num_list that have...
def sum_gt_avg(num_list): Implement a function that returns the sum of the numbers in num_list that have a value greater than the average value in the list. • Parameters: num_list is a list of numbers (mixed integers and floats) • Examples: sum_gt_avg([1,2,3,4,5]) → 9 # 4+5 sum_gt_avg([1,2,3,-4,5]) → 10 # 2+3+5 sum_gt_avg([-1,-2,-3,-4,-5]) → -3 # -1-2 in python
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT