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

猜你喜欢

转载自blog.csdn.net/qq_41998576/article/details/81278987