stdio.h中的remainder函数(全局变量定义冲突)

 今天在写计算分数的精确值代码时,用remainder定义了一个全局变量数组remainder[101],然后程序报错,说内建函数 ‘remainder’ 未被声明为函数,经过多次调试和检查代码也不能解决。

最后通过网络我查到了在stidio.h的头文件中,有一个remainder的函数

  • 函数功能:返回一个整数除以另一个整数之后产生的余数。

 

  • 函数语法:remainder ( int a, int b );

而在我的代码中,remainder是一个数组,用来存放除法的余数,与头文件的函数冲突

所以定义全局变量时,要检查与头文件中的函数是否冲突

最后我将remainder 改为remainders,解决了问题

#include <stdio.h>

int remainders[101], quotient[101];

int main() 
{
    int m, n, i, j;

    printf("Please input a fraction (m/n) (< 0 < m < n <= 100):");
    scanf("%d/%d", &m, &n);
    printf("%d/%d it's accuracy value is :0.", m, n);

    for(i = 1; i <= 100; i++)
    {
        remainders[m] = i;
        m *= 10;
        quotient[i] = m/n;
        m = m % n;

        if(m == 0)
        {
            for(j = 1; j <= i; j++)
            {
                printf("%d", quotient[j]);
            }

            break;
        }

        if(remainders[m] != 0)
        {
            for(j = 1; j <= i; j++)
            {
                printf("%d", quotient[j]);
            }

            printf("\n\tand it is infinite cyclic fraction from %d\n", remainders[m]);
            printf("\tdigit to %d digit after decimal point.\n", i);

            break;
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值