【问题标题】:how to write a function for numbers如何为数字编写函数
【发布时间】:2015-07-24 01:38:21
【问题描述】:

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

【问题讨论】:

  • 我投票决定将此问题作为题外话结束,因为有关“如何开始”、“接下来要学习什么”或“使用哪种技术”的问题都是以讨论为导向的问题,涉及的答案要么基于意见,要么都同样有效。

标签: c++ function integer


【解决方案1】:

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

【讨论】:

  • 非常感谢 Tas,我想是这样的,但我不确定!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-10
  • 2011-10-17
  • 2017-10-10
相关资源
最近更新 更多