how to write c++find the maximum,minimum,sum and average of 3 numbers

1 answer

Here's a sample code to find the maximum, minimum, sum and average of 3 numbers:

```c++
#include <iostream>
using namespace std;

int main() {
int num1, num2, num3;
int sum, average;

// Input three numbers
cout << "Enter three numbers: ";
cin >> num1 >> num2 >> num3;

// Find maximum number
int max = num1;
if (num2 > max)
max = num2;
if (num3 > max)
max = num3;
cout << "Maximum number is " << max << endl;

// Find minimum number
int min = num1;
if (num2 < min)
min = num2;
if (num3 < min)
min = num3;
cout << "Minimum number is " << min << endl;

// Find sum
sum = num1 + num2 + num3;
cout << "Sum is " << sum << endl;

// Find average
average = sum / 3;
cout << "Average is " << average << endl;

return 0;
}
```

In this code, we first input three numbers using the `cin` statement. Then, we find the maximum and minimum using simple `if` statements. Next, we find the sum of the three numbers using the `+` operator and store it in the `sum` variable. Finally, we find the average by dividing the sum by 3 and store it in the `average` variable.