我正在尝试使用泰勒级数为 sin x 编写一个 c 程序,但在执行程序时无法找出我的错误

问题描述

首先,我定义了 pi 和一个名为 fact 的函数,用于查找阶乘值。 使用泰勒级数我们有 sin(x)= x-(x^3)/3! + (x^5)/5! - ......直到第 10 个学期。 nemo 是下列术语的分子缩写,deno 是分母的缩写。 value 存储了 sin(x) 的值。

这是我尝试编写的代码:

#include<stdio.h>
#include<math.h>

#define pi 3.142

int fact(int);

int main()
{
    int i,j;
    float x,value,nume,deno;
    printf("Enter the value for sin x in degrees: \t");
    scanf("%f",&x);
    x= (pi * x)/100;
    value = 0;
    i=1;
    while(i== 1)
        value = value+ x;
    i = 2;
    for(i=2; i<=10; i++)
    {
        while (i%2 !=0)
        {

            nume = pow(x,i);
            deno = fact(i);
            for(j = 2; j<i; j++)

                if(j%2 == 0)
                value = value - (nume/deno);
            else
                value = value + (nume/deno);

            nume = 0;
            deno = 0;
        }

    }
    printf("value of sin x is : \t");
    printf("%f",value);
    return 0;
}

int fact(int n)
{
    if(n==0)
        return 1;
    else
        return (n*fact(n-1));
}

无法弄清楚出了什么问题。当我执行它时,它只打印以度为单位输入 sin x 的值请帮我修复此代码。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...