سینوس و کسینوس تا 8 رقم اعشار - هفت خط کد انجمن پرسش و پاسخ برنامه نویسی

سینوس و کسینوس تا 8 رقم اعشار

0 امتیاز

برنامه ای بنویسید که یک عدد را بر حسب درجه ورودی گرفته و مقدار سینوس و کسینوس آن را تا دقیقا ۸ رقم در اعشار چاپ کند

سوال شده آذر 17, 1399  بوسیله ی shyda (امتیاز 16)   3 3 3

1 پاسخ

0 امتیاز

باید با بسط تیلور پیاده سازی بشه به صورت زیر:

فرمول :

Sin

پیاده سازی sin :

#include <iostream> 
#include <math.h> 
using namespace std; 
  
// Function for calculating sin value 
void cal_sin(float n) 
{     
    double accuracy = 0.00000001, denominator, sinx, sinval; 
      
    // Converting degrees to radian 
    n = n * (3.142 / 180.0);  
  
    double x1 = n; 
      
    // maps the sum along the series 
    sinx = n;          
      
    // holds the actual value of sin(n) 
    sinval = sin(n);     
    int i = 1; 
    do
    { 
        denominator = 2 * i * (2 * i + 1); 
        x1 = -x1 * n * n / denominator; 
        sinx = sinx + x1; 
        i = i + 1; 
    } while (accuracy <= fabs(sinval - sinx)); 
    cout << sinx; 
} 
  
// Main function 
int main() 
{ 
    double  n = 90; 
    cal_sin(n); 
    return 0; 
}

 

فرمول :

Cos

پیاده سازی cos:

#include <iostream> 
#include <math.h> 
using namespace std; 
  
// Function for calculation 
void cal_cos(float n) 
{ 
    double accuracy = 0.00000001, x1, denominator, cosx, cosval; 
      
    // Converting degrees to radian 
    n = n * (3.142 / 180.0); 
      
    x1 = 1; 
      
    // maps the sum along the series 
    cosx = x1;          
      
    // holds the actual value of sin(n) 
    cosval = cos(n); 
    int i = 1; 
    do
    { 
        denominator = 2 * i * (2 * i - 1); 
        x1 = -x1 * n * n / denominator; 
        cosx = cosx + x1; 
        i = i + 1; 
    } while (accuracy <= fabs(cosval - cosx)); 
    cout << cosx; 
} 
  
// Main function 
int main() 
{ 
    double  n = 30; 
    cal_cos(n); 
}  

 

پاسخ داده شده آذر 21, 1399 بوسیله ی 13mody (امتیاز 256)   8 36 54
...