首页 > 编程语言 > 详细

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

时间:2021-03-30 00:30:33      阅读:23      评论:0      收藏:0      [点我收藏+]

 

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;
}

技术分享图片

 

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!