6-6 利用指针找最大值 (10 分)
 

本题要求实现一个简单函数,找出两个数中的最大值。

函数接口定义:

void findmax( int *px, int *py, int *pmax );

其中pxpy是用户传入的两个整数的指针。函数findmax应找出两个指针所指向的整数中的最大值,存放在pmax指向的位置。

裁判测试程序样例:

#include <stdio.h>

void findmax( int *px, int *py, int *pmax );

int main()
{
int max, x, y; scanf("%d %d", &x, &y);
findmax( &x, &y, &max );
printf("%d\n", max); return 0;
} /* 你的代码将被嵌在这里 */

输入样例:

3 5

输出样例:

5

void findmax( int *px, int *py, int *pmax ){
*pmax=*px>*py?*px:*py;
}

PTA 利用指针找最大值的更多相关文章

  1. 【C++】利用指针实现通过函数改变多个参数的值

    写惯了python,对于C++的语法越来越生疏,不同于python中函数可以return多个变量,C++的函数要想返回多个参数可以利用指针实现. 因为在函数内部的变量都是局部变量,所以当参数传入函数中 ...

  2. C++利用指针突破私有成员访问限制

    C++ 面向对象的一大特性就是封装,使用不同的访问控制符来控制外接对其的访问权限.比如: 1 class A 2 { 3 public: 4 A(): i(10){} 5 void print(){ ...

  3. 利用指针突破C++编译器的防线

    C++ 面向对象的一大特性就是封装,使用不同的访问控制符来控制外接对其的访问权限.比如: class A { public: A(): i(){} void print(){ cout << ...

  4. 39 编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数1/1+1/3+...+1/n(利用指针函数)

    题目:编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数1/1+1/3+...+1/n(利用指针函数) public class _039PrintFu ...

  5. POJ1064 Cable master 【二分找最大值】

    题目:题目太长了! https://vjudge.net/problem/POJ-1064 题意分析:给了你N根长度为小数形式的棍子,再给出了你需要分的棍子的数量K,但要求你这K根棍子的长度必须是一样 ...

  6. sort-list——链表、快慢指针找中间、归并排序

    Sort a linked list in O(n log n) time using constant space complexity. 链表,快慢指针找中点,归并排序. 注意判断条件fast-& ...

  7. 编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数1/1+1/3+...+1/n(利用指针函数)

    *题目:编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数1/1+1/3+...+1/n(利用指针函数) public class 第三十九题按条件计算 ...

  8. Leetcode之深度优先搜索(DFS)专题-515. 在每个树行中找最大值(Find Largest Value in Each Tree Row)

    Leetcode之深度优先搜索(DFS)专题-515. 在每个树行中找最大值(Find Largest Value in Each Tree Row) 深度优先搜索的解题详细介绍,点击 您需要在二叉树 ...

  9. LeetCode 515. 在每个树行中找最大值(Find Largest Value in Each Tree Row)

    515. 在每个树行中找最大值 515. Find Largest Value in Each Tree Row 题目描述 You need to find the largest value in ...

随机推荐

  1. 015.NET5_MVC_Razor局部视图

    局部视图 1. 可以增加代码的重用性 如何定义? 1.添加一cshtml文件 2. 在页面中调用局部视图:@html.Partial("局部视图的名称") 问题:局部视图中不能访问 ...

  2. Adaptive Threshold

    Adaptive Threshold 1. Otsu's Binarization: Using a discriminant analysis to partition the image into ...

  3. CSS BFC in depth

    CSS BFC in depth BFC (Block Formatting Context) https://developer.mozilla.org/en-US/docs/Web/Guide/C ...

  4. js function call hacker

    js function call hacker you don't know javascript function https://developer.mozilla.org/en-US/docs/ ...

  5. js binary search algorithm

    js binary search algorithm js 二分查找算法 二分查找, 前置条件 存储在数组中 有序排列 理想条件: 数组是递增排列,数组中的元素互不相同; 重排 & 去重 顺序 ...

  6. Flutter for web

    Flutter for web https://flutter.dev/web https://github.com/flutter/flutter_web Dart https://github.c ...

  7. WebView & iframe

    WebView & iframe https://developer.android.com/reference/android/webkit/WebView.html Web-based c ...

  8. push notifications

    push notifications https://developers.google.com/web/fundamentals/push-notifications/ Push API https ...

  9. 「NGK每日快讯」12.18日NGK公链第45期官方快讯!

  10. call、apply和bind的实现

    call方法 基础版, 只能修改指向,不能传参 Function.prototype.myCall = function(context) { // 获取调用者,这里为bar context.fn = ...