HTML 求出求两个数中的最大值;求出三个数中的最大值。a)定义getMax(n1, n2)函数,比较2个数中谁最大,返回最大值。 b)调用getMax(6.98,6.99)。 c)定义getMax1(a,b,c)函数,比较3个数中谁最大,返回最大值。 d)调用getMax1(40,70,10) 在控制台输出
时间: 2024-03-01 11:50:44 浏览: 26
a) HTML 不支持函数定义,但是可以用 JavaScript 来实现这个功能。
```javascript
function getMax(n1, n2) {
return (n1 > n2) ? n1 : n2;
}
```
b) 调用 `getMax(6.98,6.99)`,返回值为 6.99。
c) 同样使用 JavaScript 实现 getMax1 函数。
```javascript
function getMax1(a, b, c) {
return (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
}
```
d) 调用 `getMax1(40,70,10)`,输出结果为 70。
相关问题
用python定义一个getmax函数,返回三个数中的最大值
好的,下面是用 Python 定义一个 `getmax` 函数,该函数返回三个数中的最大值:
```python
def getmax(a, b, c):
return max(a, b, c)
```
你可以调用该函数并传入三个参数,如下所示:
```python
print(getmax(1, 2, 3)) # 输出:3
```
用C语言求两个数中最大值函数
以下是两个用C语言求两个数中最大值的函数的例子:
1.自定义函数
```c
#include<stdio.h>
int get_max(int x, int y) {
if (x > y) {
return x;//若最大值为x则返回x
} else {
return y;//否则返回y
}
}
int main() {
int a, b;
printf("请输入a,b的值,a与b之间用逗号隔开\n");
scanf("%d,%d",&a,&b);
int max = get_max(a, b);//对函数的调用
printf("最大值为:%d",max);
return 0;
}
```
2.使用三目运算符的函数
```c
#include<stdio.h>
int getMax(int x, int y) {
int z=x > y ? x : y; //三目运算符
return z;
}
int main() {
int a = 10,b=20;
int max=getMax(a, b);
printf("最大值max=%d\n",max);
return 0;
}
```
相关推荐
![md](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)