内置函数、形参实参

函数三要素:

1、返回值类型

2、函数名

3、参数列表

#include<stdio.h>
/*函数原型
*1、函数原型的定义与头部类似,最后以分号结尾
*2、函数原型中的参数名称可以省略,只写参数类型
*/
int sum(int ,int );
int main()
{
    
}
//函数定义
int sum( int num1,int num2)
{
    //函数实现的代码 
}

计算图形的面积

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//函数原型
void calcCircle();
void calcRectangle();
//函数实现
void calcCircle()
{
    double radius,s;
    scanf("%lf",&radius);

    s = 3.14 * pow(radius,2);
    printf("%.2lf", s);
}

void calcRectangle()
{
    double width,height;
    double s;
    scanf("%lf%lf",&width, &height);
    s = width * height;
    printf("%.2lf", s);

}

int main()
{
    //需要返回值吗
    //函数名是什么
    //需要给这个函数参数吗
    calcRectangle();
    calcCircle();
    return 0;
}

形参实参,带返回值的函数

#include<stdio.h>
#include<stdlib.h>

double power(double ,int );

int main()
{
    printf("%d %d %.2lf",5,2,power(5,2));

    return 0;
}
double power(double num1, int num2)
{
    double result = 1;
    int i;
    for(i = 0; i < num2; i++)
    {
        result *= num1; //累乘  
    }
    
    return result;//返回值
}
原文地址:https://www.cnblogs.com/18191xq/p/11760922.html