首页 > 解决方案 > 使用霍纳规则评估多项式

问题描述

这个问题的第二个循环不起作用。我正在尝试打印出对霍纳规则的评估,但由于第二个循环,我没有得到正确的输出。

#include <stdio.h>

int main()
{
    float a[100], x, sum = 0;
    int n;
    printf("enter the degree of polynomial : ");
    scanf("%d", &n);

    printf("enter the coefficient of polynomial : \n ");

    for (int i = n; i <= n; i--)

    {
        printf("enter the coefficiient for x^%d\n", i);
        scanf("%f", &a[i]);
        if (i == 0)
        {
            break;
        }
    }

    printf("enter the value : ");
    scanf("%f", &x);

    for (int i = n ; i < n; i++)
    {
        sum = (sum + a[i]) * x;
    }

    printf("the vlaue of polynomial is %f\n", sum);
    return 0;
}
  

标签: data-structuresclang

解决方案


推荐阅读