網站首頁 編程語言 正文
c語言函數求兩個數的最大值
/*
聲明一個求兩個數最大值的函數
if(a>b){
printf("最大值是 %d",a);
} else{
printf("最大值是 %d",b);
}
*/
#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);
}
c語言?求十個數中的最大值
解題思路
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;
}
運行結果:
總結
原文鏈接:https://dapenglee.blog.csdn.net/article/details/90665927
相關推薦
- 2022-09-15 python實現簡單的計算器功能_python
- 2023-01-23 python操作excel之xlwt與xlrd_python
- 2022-10-25 React?中?setState?的異步操作案例詳解_React
- 2022-10-12 C#設計模式之建造者模式生成器模式示例詳解_C#教程
- 2022-12-09 CALL命令無法在PowerShell中使用的原因及解決方法_DOS/BAT
- 2022-12-08 oracle自動生成uuid的實現方法_oracle
- 2022-09-09 python中.format()方法使用詳解_python
- 2022-08-03 Django框架中模型的用法_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支