如何为数字编写函数

时间:2015-05-13 00:03:10

标签: c++ function integer

编写一个从用户读取正数的函数,并返回最大数字并输出。函数签名应该是int maximum(); 所以我的问题是,我不确定如何编写函数。我会做一个像main();或者是别的什么?

1 个答案:

答案 0 :(得分:0)

您已经获得了函数签名: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;
}