C Math kütüphanesi olmadan Taylor ile Cosx hesaplama

Jacquez

Hectopat
Katılım
19 Ekim 2019
Mesajlar
125
Yer
Ankara
Daha fazla  
Cinsiyet
Erkek
Nerede hata yaptığımı bulabilir misiniz?

Kod:
#include<stdio.h>

float my_pow(float x, float y);
float my_fac(float z);
double my_cos(float t);


int main(void){
    float a;
  
  
    printf("Enter degree for cosine : ");
    scanf("%f",&a);
  
    printf("%f",my_cos(a));
  
    return 0;
}


float my_pow(float x, float y){
  
    int counter;
    double powe = 1;
  
    for(counter = 1 ; counter <= y ; counter++ ){
        powe *= x;
    }
    return powe;
}


float my_fac(float z){
  
    int counter3;
    double fin = 1;
  
    for(counter3 = 1; counter3 <= z; counter3++ ){
        fin *= counter3;
    }
    return fin;
}
double my_cos(float t){
  
    int counter2;
    int counter4;
    double poorNum = 1;
  
    for(counter4 = 4 ; counter4 <= 50; counter4 += 4){
        poorNum += my_pow(t,counter4) / my_fac(counter4);
    }
  
    for(counter2 = 2 ; counter2 <= 50; counter2 += 4){
        poorNum -= my_pow(t,counter2) / my_fac(counter2);
    }
  
  
  
  
    return poorNum;
}
 
Ufak bir arştırma yaptım. taylor hesaplamada degree değil radian giriliyor. sen degree ile işlem yapıyorsun. yani aldıgın sayıyı pi/180 ile çarpman gerek.
 
Bu siteyi kullanmak için çerezler gereklidir. Siteyi kullanmaya devam etmek için çerezleri kabul etmelisiniz. Daha Fazlasını Öğren.…