浙大版《C语言程序设计(第3版)》题目集

练习5-2 找两个数中最大者

本题要求对两个整数a和b,输出其中较大的数。

函数接口定义:

int max( int a, int b );

其中ab是用户传入的参数,函数返回的是两者中较大的数。

裁判测试程序样例:

#include <stdio.h>

int max( int a, int b );

int main() {

int a, b;

scanf("%d %d", &a, &b);

printf("max = %d\n", max(a, b));

return 0; }

/* 你的代码将被嵌在这里 */

输入样例:

复制代码
-5 8

输出样例:

复制代码
max = 8

#include <stdio.h>

#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int max(int a,int b);

int main(int argc, char *argv[]) {

int a,b;

scanf("%d %d",&a,&b);

printf("max = %d\n",max(a,b));

return 0;

}

int max(int a,int b){

if(a>b){

return a;

}

return b;

}

相关推荐
木子.李3472 小时前
排序算法总结(C++)
c++·算法·排序算法
闪电麦坤953 小时前
数据结构:递归的种类(Types of Recursion)
数据结构·算法
freyazzr4 小时前
C++八股 | Day2 | atom/函数指针/指针函数/struct、Class/静态局部变量、局部变量、全局变量/强制类型转换
c++
Gyoku Mint4 小时前
机器学习×第二卷:概念下篇——她不再只是模仿,而是开始决定怎么靠近你
人工智能·python·算法·机器学习·pandas·ai编程·matplotlib
纪元A梦4 小时前
分布式拜占庭容错算法——PBFT算法深度解析
java·分布式·算法
fpcc4 小时前
跟我学c++中级篇——理解类型推导和C++不同版本的支持
开发语言·c++
px不是xp5 小时前
山东大学算法设计与分析复习笔记
笔记·算法·贪心算法·动态规划·图搜索算法
终焉代码5 小时前
STL解析——list的使用
开发语言·c++
DevangLic5 小时前
【 *p取出内容 &a得到地址】
c++