Bài 19: Tính S(n) = 1 + x + x^3/3! + x^5/5! + … + x^(2n+1)/(2n+1)!

Bài 19: Tính S(n) = 1 + x + x^3/3! + x^5/5! + … + x^(2n+1)/(2n+1)!

Bài tập 19 (Dạng bài tập này giúp các bạn giỏi về: Lưu đồ thuật toán)

Tính S(n) = 1 + x + x^3/3! + x^5/5! + … + x^(2n+1)/(2n+1)!

Cài đặt

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
    int i, n;
    float x, S, T;
    long M, N;
    printf("\nNhap x: ");
    scanf("%f", &x);
    do
    {
    printf("\nNhap n(n >= 1) : ");
    scanf("%d", &n);
      if(n < 1)
      {
          printf("\n N phai >= 1. Xin nhap lai !");
      }

    }while(n < 1);

    S = 1 + x;
    N = 1;
    i = 1;

    while(i <= n)
    {
        T = pow(x, (2 * i + 1));
M = i * 2 + 1;
N = N * M * (M - 1);
S = S + T/N;
i++;
    }
    printf("\nTong la %f", S);
    getch();
    return 0;
}

Cách khác

int main()
{
    int n, x, i, j;
    unsigned long t1, t2;
    float S;
    i = 1;
    j = 1;
    S = 1;
    cout << "Enter x, n: ";
    cin >> x >> n;
    t1 = x;
    t2 = 1;
    while (i <= n+1)
    {
        S = S + (float) t1 / t2;
        t1 = t1 * x * x;
        j = i * 2;
        t2 = t2 * j * (j + 1);
        i++;
    }
    cout << "S = " << S;

    // END MAIN
    system("pause");
}
Bạn thấy bài viết này như thế nào?: 
Average: 8.9 (124 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Thẻ meta để làm SEO, ý nghĩa của một số thẻ meta năm 2015

Thẻ meta để làm SEO, ý nghĩa của một số thẻ meta năm 2015

Meta tag là thẻ dùng để cung cấp các thông tin về website một cách tóm gọn đối với các trình duyệt

Sony chính thức công bố loạt ultrabook Vaio chạy Windows 8

Sony vừa chính thức công bố loạt ultrabook mới có thương hiệu Vaio chạy hệ điều hành Windows 8 sắp ra mắt của Microosoft, bao gồm Vaio 11 Duo, T-series, E-series, cùng với đó là MTXT S-series.

Giới thiệu 5 Hurdles cần phải biết tại Drupal 8

Giới thiệu 5 Hurdles cần phải biết tại Drupal 8

This means that if you have a 5-year-old Drupal 6 site, you will find major value in upgrading directly to Drupal 8. Many other benefits can justify the cost, including an easier to administer, responsive site.

Công ty diệt chuột T&C

 

Diet con trung