目录C语言函数求两个数的最大值c语言求十个数中的最大值解题思路具体代码总结c语言函数求两个数的最大值 #include <stdio.h> max(int a,int
#include <stdio.h>
max(int a,int b){
//三木运算来求出最大值
int z= a>b?a:b;
printf("最大值是 %d",z);
}
main(){
int x,y;
scanf("%d %d",&x,&y);
//调用 max函数
max(x,y);
}
1、设置一个长度为10的数组arr【10】;
2、循环输入十个数字对数组赋值;
3、将数组首元素的值赋给max,后续元素依次与max做比较,若arr【i】>max则交换两值;
4、遍历后得到最大值max。
#include<stdio.h>
#include<stdlib.h>
int main(){
int arr[10];
int i = 0;
int max = 0;
printf("请输入十个整数:\n");
for (i; i < 10; i++){
scanf_s("%d", &arr[i]);
}
max = arr[0];
for (i = 1; i < 10; i++){
if (arr[i] > max){
max = arr[i];
}
}
printf("最大数为:%d\n", max);
system("pause");
return 0;
}
运行结果:
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: c语言函数如何求两个数的最大值
本文链接: https://www.lsjlt.com/news/174310.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0