浙大版《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;

}

相关推荐
蓝风破云4 分钟前
模拟实现STL中的list容器
c语言·数据结构·c++·链表·迭代器·list·iterator
DjangoJason6 分钟前
每日算法题【二叉树】:二叉树的最大深度、翻转二叉树、平衡二叉树
数据结构·算法·链表
☆璇15 分钟前
【C++】C++的IO流
开发语言·c++
HalvmånEver25 分钟前
盛最多水的容器:双指针法的巧妙运用(leetcode 11)
c++·学习·leetcode
励志不掉头发的内向程序员1 小时前
STL库——stack/queue(类函数学习)
开发语言·c++·学习
努力努力再努力wz1 小时前
【c++进阶系列】:万字详解异常
java·linux·运维·服务器·开发语言·c++
Peter_Deng.1 小时前
C语言 - 输出参数详解:从简单示例到 alloc_chrdev_region
c语言·开发语言
麦麦在写代码2 小时前
联合体Union
c语言
CoovallyAIHub2 小时前
GQNN 框架:让 Python 开发者轻松搭建量子神经网络
深度学习·算法·计算机视觉
CoovallyAIHub2 小时前
轻量级注意力模型HOTSPOT-YOLO:无人机光伏热异常检测新SOTA,mAP高达90.8%
深度学习·算法·计算机视觉