zoukankan      html  css  js  c++  java
  • c语言中函数的定义和调用(计算两个数中的较大值)

    1、函数定义和函数调用

    #include <stdio.h>
    
    int max2(int a, int b)    ## 函数头:返回类型, 函数名,形参声明a,形参声明b
    {
        if (a > b)
            return a;         ## 函数体(复合语句)        ## 函数定义
        else
            return b;
    }
    
    int main(void)
    {
        int n1, n2;
        puts("please input two integer!");
        printf("n1 = "); scanf("%d", &n1);
        printf("n2 = "); scanf("%d", &n2);
        
        printf("larger is: %d\n", max2(n1,n2));    ## 函数调用, n1和n2为实参。
    return 0
    ; }

    #include <stdio.h>
    
    int max2(int a, int b)
    {
        int max;
        if (a > max)
            max = a;
        if (b > max)
            max = b;
        return max;
    }
    
    int main(void)
    {
        int n1, n2;
        puts("please input two integers!");
        printf("n1 = "); scanf("%d", &n1);
        printf("n2 = "); scanf("%d", &n2);
        
        printf("larger is: %d\n", max2(n1, n2));
        return 0;
    }

    #include <stdio.h>
    
    int max2(int a, int b)
    {
        int max = a;
        if (b > max)
            max = b;
        return max;
    }
    
    int main(void)
    {
        int n1, n2;
        puts("please input two integers!");
        printf("n1 = "); scanf("%d", &n1);
        printf("n2 = "); scanf("%d", &n2);
        
        printf("larger is: %d", max2(n1, n2));
        return 0;
    }

    #include <stdio.h>
    
    int max2(int a, int b)
    {
        return a > b ? a : b;
    }
    
    int main(void)
    {
        int n1, n2;
        puts("please input two integers!");
        printf("n1 = "); scanf("%d", &n1);
        printf("n2 = "); scanf("%d", &n2);
        
        printf("larger is: %d\n", max2(n1, n2));
        return 0;
    }
  • 相关阅读:
    poj 3261 Milk Patterns 后缀数组+二分
    poj 2774 Long Long Message(后缀数组入门题)
    hdu 5719 Arrange
    hdu 5720 Wool
    DROP TABLE 恢复
    MySQL数据库改名的三种方法
    MySQL 误操作后数据恢复(update,delete忘加where条件)
    MySQL常用SQL语句优化
    EXPLAIN 命令详解
    mysql sql语句大全
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14572095.html
Copyright © 2011-2022 走看看