c语言中没有形参的函数(例题:逆向输出正整数)

1、c语言中没有形参的函数

#include <stdio.h>

int func1(void)     ## 没有形参的函数
{
    int i;
    puts("please input an integer.");
    do
    {
        printf("i = "); scanf("%d", &i);
        if (i <= 0)
            puts("the range is: > 0");
    }
    while (i <= 0);
    return i;
}

int func2(int x)
{
    int i = 0;
    while (x > 0)
    {
        i = i * 10 + x % 10;
        x /= 10;
    }
    return i;
}

int main(void)
{
    int x = func1();     ## 调用时不需要添加形参
    printf("the reversed: %d\n", func2(x));
    return 0;
}

#include <stdio.h>

int func1(void)
{
    int i;
    puts("please input an integer.");
    do
    {
        printf("i = "); scanf("%d", &i);
        if (i <= 0)
            puts("the range is > 0");
    }
    while (i <= 0);
    return i;
}

int func2(int x)
{
    int i = 0;
    if (x > 0)
    {
        do
        {
            i = i * 10 + x % 10;
            x /= 10;
        }
        while (x > 0);
    }
    return i;
}

int main(void)
{
    int x = func1();
    printf("the reversed : %d \n", func2(x));
    return 0;
}

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14594338.html