如何为数字编写函数

how to write a function for numbers

编写一个函数,从用户那里读取正数,returns最大的数字并输出。函数签名应该是 int largest(); 所以我的问题是,我不确定如何编写函数。我会做一些类似 into main(); 的事情吗?或者是别的什么?

您已经获得了函数签名:int largest(),因此这正是您编写函数的方式(与 int main(); 完全相同):

// Declares the function
int largest();
// Defines the function:
int largest()
{
    // The function MUST return an int (or something convertible) otherwise it will not compile
    return 0;
}

或者您可以将声明与定义结合起来:

int largest()
{
   return 0;
}