IS IT CORRECT? Write a function to show the max number in ten input numbers.
IS IT CORRECT?
- Write a function to show the max number in ten input numbers.
Answer:
#include <iostream>
#include <algorithm>
using namespace std;
int numbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int maxNumber = *max_element(numbers, numbers + 10);
int findMax(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) {
int max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
if (d > max) {
max = d;
}
if (e > max) {
max = e;
}
if (f > max) {
max = f;
}
if (g > max) {
max = g;
}
if (h > max) {
max = h;
}
if (i > max) {
max = i;
}
if (j > max) {
max = j;
}
return max;
}
int main() {
cout << findMax(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) << endl;
return 0;
}
Step by step
Solved in 2 steps