作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我需要在函数 main > my_isneg 中插入一些内容来调用 my_isneg 函数。我该怎么做?
#include <unistd.h>
void my_putchar (char c)
{
write (1, &c, 1);
}
int my_isneg (int n)
{
if (n < 0) {
my_putchar (78); }
else {
my_putchar (80);
}
}
int main (void)
{
my_isneg();
}
最佳答案
有点不清楚你在问什么,但也许你想要这个:
...
// print 'N' 1 if the number n is strictly negative, print 'P' otherwise
int my_isneg(int n)
{
if (n < 0) {
my_putchar('N'); // use 'N' instead of 80 (it's more readable)
}
else {
my_putchar('P'); // use 'P' instead of 80
}
}
int main(void)
{
my_isneg(-1);
my_isneg(1);
my_isneg(2);
}
输出
NPP
或者可能是这个,它更接近于名称 my_isneg
:
...
// return 1 if the number n is strictly negative
int my_isneg(int n)
{
return n < 0;
}
int main(void)
{
if (my_isneg(-1))
my_putchar('N');
else
my_putchar('P');
if (my_isneg(1))
my_putchar('N');
else
my_putchar('P');
}
输出
NP
关于c - 如何在 main 函数中调用 int 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52642615/
我是一名优秀的程序员,十分优秀!