/*
C程序源代码格式的一般情况如下:
预编译语句
宏定义常量
函数的声明放在这里
main函数
函数的实现放这里
*/
函数的分类
1.库函数 printf scanf
2.数学库函数 #include<math.h> (P103)
3.自定义函数:用户在程序中需要而编写的函数
/*
C语言函数的定义:
语法:
返回值类型 函数名(参数类型参数名1,参数类型参数名2,...)
{
实现函数的代码
return 返回值;
}
*/
//在main函数的前面,我们需要将程序需要用到的函数,声明或定义出来
//有返回值有参数类型
int getMax(int a,int b,int c)
{
//auto
int max = a;
if (max < b)
{
max = b;
}
if (max < c)
{
max = c;
}
return max;
}
//无返回值无参数类型
void print()
{
printf("我是无返回值无参数类型的\n");
}
//有返回值无参数类型
int getSum()
{
int sum = 0 ;
for (int i = 1; i<= 100; i++)
{
sum += i;
}
return sum;
}
//无返回值有参数类型
void printChar(char alphabet)
{
printf("alphabet = %c\n",alphabet);
}